Q: One of our clients provides us with PDF files in which each page
contains the Front and Back; we are currently using another software
to cut/split PDF pages but it is very slow when we get file with 3000+
pages and it does not work relaibly. Can I use PDFNet (http://
www.pdftron.com/pdfnet) to cut PDF pages?
--------
A: You can use the following code snippet as a starting point:
// C# sample to cut/split PDF pages (VB, JAVA, C/C++ is along the same
lines).
PDFDoc doc = new PDFDoc("my.pdf");
doc.InitSecurityHandler();
int pgnum = doc.GetPageCount();
for (int i = 1; i <= pgnum; ++i)
{
// Clone the page
PageIterator itr = doc.GetPageIterator(i * 2 - 1);
Page pg = itr.Current();
itr.Next();
doc.PageInsert(itr, pg);
// Adjust the crop box on the first page
Rect box = pg.GetCropBox();
box.x2 = (box.x1 + box.x2) / 2;
pg.SetCropBox(box);
// Adjust the crop box on the second page
pg = doc.GetPage(i * 2);
box = pg.GetCropBox();
box.x1 = (box.x1 + box.x2) / 2;
pg.SetCropBox(box);
}
doc.Save("out.pdf", 0);
doc.Close();
To download full sample code:
http://groups.google.com/group/pdfnet-sdk/web/PDFPageCut.cs
A relevant sample in PDFNet SDK i RectTest sample: