-
-
Save jlollis/47081309fc7966b31058c27c055f99bb to your computer and use it in GitHub Desktop.
Merge PDFs with PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Not my code, this is from Mike Pfeiffer - http://mikepfeiffer.net/2010/03/how-to-merge-pdf-files-using-powershell-and-pdfsharp/ | |
#Requires PDFSharp assembly libraries http://sourceforge.net/projects/pdfsharp/ | |
#You need to load the assembly before you can use the function | |
# | |
#Merge-PDF -path c:\pdf_docs -filename c:\saved_docs.pdf | |
Add-Type -Path C:\assemblies\PdfSharp.dll | |
Function Merge-PDF { | |
Param($path, $filename) | |
$output = New-Object PdfSharp.Pdf.PdfDocument | |
$PdfReader = [PdfSharp.Pdf.IO.PdfReader] | |
$PdfDocumentOpenMode = [PdfSharp.Pdf.IO.PdfDocumentOpenMode] | |
foreach($i in (gci $path *.pdf -Recurse)) { | |
$input = New-Object PdfSharp.Pdf.PdfDocument | |
$input = $PdfReader::Open($i.fullname, $PdfDocumentOpenMode::Import) | |
$input.Pages | %{$output.AddPage($_)} | |
} | |
$output.Save($filename) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment