Merge All Documents Within Folder | PowershellByteScout PDF Extractor SDK

Merge All Documents Within Folder | Powershell

MergeAllDocumentsWithinFolder.bat:

@echo off

if "%~1"=="" (
	echo -----------------------------------------------------
	echo Invalid parameter!
	echo -----------------------------------------------------
	echo Usage: MergeAllDocumentsWithinFolder.bat folder_name
	echo Example: MergeAllDocumentsWithinFolder.bat "PDFDocs"
	echo -----------------------------------------------------
	if not "%NOPAUSE%"=="1" pause
	exit /b 1
)

powershell -NoProfile -ExecutionPolicy Bypass -Command "& .\MergeAllDocumentsWithinFolder.ps1" "%1"
echo Script finished with errorlevel=%errorlevel%

pause
        

MergeAllDocumentsWithinFolder.ps1:

#*******************************************************************************************#
#                                                                                           #
# Download Free Evaluation Version From: https://bytescout.com/download/web-installer       #
#                                                                                           #
# Also available as Web API! Get Your Free API Key: https://app.pdf.co/signup               #
#                                                                                           #
# Copyright © 2017-2020 ByteScout, Inc. All rights reserved.                                #
# https://www.bytescout.com                                                                 #
# https://pdf.co                                                                            #
#                                                                                           #
#*******************************************************************************************#

Param (
    [Parameter(Mandatory = $true)]
    [string] $InputFolder = ""
)

#Add reference to Bytescout.PDFExtractor.dll assembly
Add-Type -Path "C:\Program Files\Bytescout PDF Extractor SDK\net4.00\Bytescout.PDFExtractor.dll"

# Check input folder exists
if ((Test-Path $InputFolder) -eq $false) {

    Write-Host "Input folder does not exist." -ForegroundColor Red
    Exit 0
}

$IncludeSubFolder = $true
$OutputFileName = "result.pdf"

# Create and activate Bytescout.PDFExtractor.DocumentMerger instance
$Merger = New-Object Bytescout.PDFExtractor.DocumentMerger
$Merger.RegistrationName = "demo"
$Merger.RegistrationKey = "demo"

try {
    $Merger.MergeFolder($InputFolder, $OutputFileName, $IncludeSubFolder)
} catch {

    Write-Host $_.Exception.Message
}

$Merger.Dispose()