[
https://issues.apache.org/jira/browse/PDFBOX-5078?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17266172#comment-17266172
]
Tilman Hausherr commented on PDFBOX-5078:
-----------------------------------------
That one must be cut on a horizontal line because the pages are rotated. Here
some new code:
{code}
public class SplitBooklet
{
public static void main(String[] args) throws IOException
{
String dir = XXXX
PDDocument document = Loader.loadPDF(new File(dir, XXXX));
PDDocument outdoc = new PDDocument();
for (PDPage page : document.getPages())
{
PDRectangle cropBoxORIG = page.getCropBox();
// make sure to have new objects
PDRectangle cropBoxLEFT = new
PDRectangle(cropBoxORIG.getCOSArray());
PDRectangle cropBoxRIGHT = new
PDRectangle(cropBoxORIG.getCOSArray());
if (page.getRotation() == 90 || page.getRotation() == 270)
{
cropBoxLEFT.setUpperRightY(cropBoxORIG.getLowerLeftY() +
cropBoxORIG.getHeight() / 2);
cropBoxRIGHT.setLowerLeftY(cropBoxORIG.getLowerLeftY() +
cropBoxORIG.getHeight() / 2);
}
else
{
cropBoxLEFT.setUpperRightX(cropBoxORIG.getLowerLeftX() +
cropBoxORIG.getWidth() / 2);
cropBoxRIGHT.setLowerLeftX(cropBoxORIG.getLowerLeftX() +
cropBoxORIG.getWidth() / 2);
}
if (page.getRotation() == 180 || page.getRotation() == 270)
{
PDPage pageRIGHT = outdoc.importPage(page);
pageRIGHT.setCropBox(cropBoxRIGHT);
PDPage pageLEFT = outdoc.importPage(page);
pageLEFT.setCropBox(cropBoxLEFT);
}
else
{
PDPage pageLEFT = outdoc.importPage(page);
pageLEFT.setCropBox(cropBoxLEFT);
PDPage pageRIGHT = outdoc.importPage(page);
pageRIGHT.setCropBox(cropBoxRIGHT);
}
}
outdoc.save(new File(dir, XXX));
outdoc.close();
document.close(); // must be after saving the destination document
}
}
{code}
Your booklet does not have the pages in sequence, so more logic is needed.
> Failure to modify cropBox when splitting a PDF Page vertically into 2 pieces
> ----------------------------------------------------------------------------
>
> Key: PDFBOX-5078
> URL: https://issues.apache.org/jira/browse/PDFBOX-5078
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.22
> Reporter: Joseph
> Assignee: Tilman Hausherr
> Priority: Major
> Fix For: 2.0.23, 3.0.0 PDFBox
>
> Attachments: 58-10-05E Not Working.pdf, 64-1212 (4).pdf,
> sample_2.pdf, screenshot-1.png
>
>
> We can able to convert A4 PDF to Booklet PDF via PrintDF open source
> ([https://github.com/Raudius/PrintDF/blob/master/src/us/raudi/printdf/PrintDF.java)]
> However not able to convert Booklet to A4 i.e that is cutting vertically of a
> Booklet PDF page and resequence all the pages.
> 1st problem is not sure how to cut veritically each and every PDF page and
> save as 2 separate PDF page or file
> 2nd re-sequence of the booklet to proper sequence as 1, 2, 3, 4, 5 by first
> identifying the actual book sequence
> (http://www.boooks.org/index.php?page=21&lng=1)
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]