Reputation: 6752
I have a pdf that I want to make into several 1 page pdfs where each page in the original pdf is now its own pdf document. I am trying to do this using itextsharp, but am having some difficulty even getting started.
Am I going about this the wrong way? Anyone know how I would go about doing this?
Thanks a ton!
Upvotes: 1
Views: 812
Reputation: 20320
using (FileStream fs = new FileStream(argPdfFileName, FileMode.Create))
{
Document doc = new Document(argReader.GetPageSize(argPdfPageNumber));
PdfCopy copy = new PdfCopy(doc, fs);
doc.Open();
PdfImportedPage page = copy.GetImportedPage(argReader, argPdfPageNumber);
copy.AddPage(page);
doc.Close();
}
Chopped this out of some working code. argReader is a PdfReader instance pointing at the source document. argPdfPageNumber is the pagenumber in question. Basically you just create a new pdf. Import the source page into it and then add it to the document and save.
Upvotes: 1
Reputation: 90193
There are two different commandline tools which can do that, both for any of the major OS platforms available.
Example commandline:
pdftk input.pdf burst output page_%04d-from-input.pdf
Example commandline:
gs \
-o page_%04d-from-input.pdf \
-sDEVICE=pdfwrite \
input.pdf
Caveats: It's only the most recent version of Ghostscript which supports this commandline syntax of %04d
for page-wise different output files + names.
pdftk
isn't able to do any PDF manipulation in the process and is very fast.
The new Ghostscript method somewhat slower, but has the advantage that it can apply a lot of its other PDF processing capabilities should you need them.
Upvotes: 1