First you will need to download PDF Sharp and build with Visual Studio the solution “BuildAll-PdfSharp.sln” and then obtaining the output PdfSharp.dll and placing in same directory as script.
Takes a specified folder of PDFs and combines them into an output file. Modify sourcePath and outputPath as necessary.
$sourcePath = "<path to folder with PDFs to merge>"
$outputPath = "<filename of final PDF>"
Add-Type -Path "$($PSScriptRoot)\PdfSharp.dll"
$pdfDestination = New-Object PdfSharp.Pdf.PdfDocument
$pdfFiles = Get-ChildItem -Path $sourcePath -Filter *.pdf
ForEach ($filename in $pdfFiles)
{
"Adding '$($filename.Fullname)'"
$pdfSource = [PdfSharp.Pdf.IO.PdfReader]::Open($filename.Fullname,[PdfSharp.Pdf.IO.PdfDocumentOpenMode]::Import)
for ($i = 0; $i -lt $pdfSource.PageCount; $i++)
{
$pdfDestination.AddPage($pdfSource.Pages[$i])
}
$pdfSource.Close()
}
$pdfDestination.Save($outputPath)