i want to split one wide PDF page into two PDF pages. My original page is wide as two A4 page size but height is normal(for A4). I trying to use IText but with no effects. Thanks for attention.
Choose “Organize Pages” > “Split.” Choose how you want to split a single file or multiple files. Name and save: Click “Output Options” to decide where to save, what to name, and how to split your file. Split your PDF: Click “OK” and then “Split” to finish.
I don't know the iText API, but you can follow these steps to get there:
Create two new copies of the existing page. This means that you have the same Resources, the same ContentStream, etc.
Get the MediaBox for the first page which is an array laid out as [llx lly urx ury].
if MediaBox[2] - MediaBox[0] == long edge of A4 page then
HalfPageWidth = MediaBox[2] - MediaBox[0];
PageCopy1.CropBox = [MediaBox[0] MediaBox[1] (MediaBox[0] + HalfPageWidth) MediaBox[3]]
PageCopy2.CropBox = [(MediaBox[0] + HalfPageWidth) MediaBox[1] MediaBox[2] MediaBox[3]]
else
HalfPageHeight = MediaBox[3] - MediaBox[1];
PageCopy1.CropBox = [MediaBox[0] MediaBox[1] MediaBox[2] (MediaBox[1] + HalfPageHeight)]
PageCopy2.CropBox = [MediaBox[0] (MediaBox[1] + HalfPageHeight)] MediaBox[2] MediaBox[3]]
Remove the original page and save these two pages. Basically, you're making two identical copies of the page and cropped each to half the page. You may also need to set the page rotation.
You can also use Ghostscript (with the addition of a PostScript code snippet to the call) for that. Commandlines required:
gs \
-o left-half.pdf \
-sDEVICE=pdfwrite \
-g5950x8420 \
-dFIXEDMEDIA \
-PDFFitPage \
-dAutoRotatePages=/None \
-c "<</PageOffset [0 0]>> setpagedevice" \
doubleup.pdf
gs \
-o left-half.pdf \
-sDEVICE=pdfwrite \
-g5950x8420 \
-dFIXEDMEDIA \
-PDFFitPage \
-dAutoRotatePages=/None \
-c "<</PageOffset [-595 0]>> setpagedevice" \
doubleup.pdf
These commandlines can easily be translated into Java or whatever code to use the appropriate GS API calls...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With