Created
February 3, 2014 13:51
-
-
Save duncansmart/8784183 to your computer and use it in GitHub Desktop.
Split PDFs into PDF per page (which can then be edited by InkScape) and merge
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
static void pdfSplitIntoPages() | |
{ | |
// EO.Pdf.Runtime.AddLicense("..."); | |
string sourceFile = @"C:\TEMP\Blah.pdf"; | |
var pdf = new PdfDocument(sourceFile); | |
var pages = pdf.Split(Enumerable.Range(1, pdf.Pages.Count-1).ToArray()); | |
var i = 1; | |
foreach (PdfDocument page in pages) | |
{ | |
string newName = Path.Combine(Path.GetDirectoryName(sourceFile), Path.GetFileNameWithoutExtension(sourceFile) + " - Page " + (i++).ToString("000") + ".pdf"); | |
page.Save(newName); | |
} | |
} | |
static void pdfMergePages() | |
{ | |
string sourcePattern = @"C:\TEMP\Blah - Page *.pdf"; | |
string targetFile = @"C:\TEMP\Blah - MERGED.pdf"; | |
var sourceFiles = Directory.EnumerateFiles(Path.GetDirectoryName(sourcePattern), Path.GetFileName(sourcePattern)) | |
.OrderBy(f => f); | |
var newDoc = PdfDocument.Merge(sourceFiles.Select(f => new PdfDocument(f)).ToArray()); | |
newDoc.Save(targetFile); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment