0

Im hoping someone can help me.

At the moment I create A4 Documents using FOP and XSLT. I have been asked to take these A4 (portrait) pages and then stitch them into an A3 booklet. So for example I have a 4 page A4 document which I need to convert into a 2 sided A3 booklet with the ability to order the first side using page 4 and 1 (side by side) and then the other side to be page 2 and 3.

I have looked at PDFBOX to see if it can do this but have had no success.

Does anyone have any ideas of how I could get the outcome that I need?

All help is appreciated!

  • *I have looked at PDFBOX to see if it can do this but have had no success.* - Have a look at the recommendations given in the comments to ["PDFBox: put two A4 pages on one A3"](http://stackoverflow.com/questions/38952984/pdfbox-put-two-a4-pages-on-one-a3). Those recommendations point to solutions using PDFBox while the only answer there points towards using a different library. – mkl Aug 16 '16 at 13:36
  • Are you going to generate A3 size pages such like book cover by XSL-FO? Or do you want to make A3 size pages PDF from existing A4 pages PDF via PDFBox? – Toshihiko Makita Aug 16 '16 at 17:10
  • Ideally I would like to take 4 A4 PDF pages (all from one PDF file) and then stitch them together to create an A3 PDF booklet (sequence mentioned above). Just not sure the best way to do this. Im going to try the method that Stefan has kindly suggested as its no problem for me to create a new A3 template which pulls the pages I need from a pdf that has already been generated. – Mike Taylor Aug 17 '16 at 08:29
  • I have an XSL that does this written for RenderX's intermediate format. If you are interested in modifying this for FOP, I would be happy to post as an answer. – Kevin Brown Aug 17 '16 at 18:05

1 Answers1

0

You can do that with FOP if you wish and if you install the PDF Images Plug-In for FOP

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <fo:layout-master-set>
        <fo:simple-page-master master-name="a3" margin-right="0mm" margin-left="0mm" margin-bottom="0mm" margin-top="0mm" page-width="42cm" page-height="29.7cm">
            <fo:region-body margin-left="0mm" margin-top="0mm" margin-bottom="0mm" margin-right="0mm"/>
        </fo:simple-page-master>
        <fo:page-sequence-master master-name="a3n">
            <fo:repeatable-page-master-alternatives>
                <fo:conditional-page-master-reference master-reference="a3" page-position="any"/>
            </fo:repeatable-page-master-alternatives>
        </fo:page-sequence-master>
    </fo:layout-master-set>
    <fo:page-sequence master-reference="a3n">
        <fo:flow flow-name="xsl-region-body">
            <fo:block-container height="29.7cm" width="20.9cm" top="0mm" left="0mm" position="absolute">
                <fo:block>
                    <fo:external-graphic content-height="29.7cm" content-width="21cm" height="29.7cm" width="21cm" src="yourpathdoc.pdf#page=2"/>
                </fo:block>
            </fo:block-container>
            <fo:block-container height="29.7cm" width="20.9cm" top="0mm" left="209mm" position="absolute">
                <fo:block>
                    <fo:external-graphic content-height="29.7cm" content-width="21cm" height="29.7cm" width="21cm" src="yourpathdoc.pdf#page=3"/>
                </fo:block>
            </fo:block-container>
            <fo:block-container>
                <fo:block font-size="0.1pt" page-break-after="always" break-after="page"> </fo:block>
            </fo:block-container>
            <fo:block-container height="29.7cm" width="20.9cm" top="0mm" left="0mm" position="absolute">
                <fo:block>
                    <fo:external-graphic content-height="29.7cm" content-width="21cm" height="29.7cm" width="21cm" src="yourpathdoc.pdf#page=4"/>
                </fo:block>
            </fo:block-container>
            <fo:block-container height="29.7cm" width="20.9cm" top="0mm" left="209mm" position="absolute">
                <fo:block>
                    <fo:external-graphic content-height="29.7cm" content-width="21cm" height="29.7cm" width="21cm" src="yourpathdoc.pdf#page=1"/>
                </fo:block>
            </fo:block-container>
        </fo:flow>
    </fo:page-sequence>
</fo:root>

Edit

In case you want it portrait for easier printing, simply switch the page-width and page-height of the simple-page-master and replace the four block-container lines containing the position="absolute" with

            <fo:block-container height="29.7cm" width="21cm" top="0mm" left="0mm" position="absolute" reference-orientation="270">
...
            <fo:block-container height="29.7cm" width="21cm" top="210mm" left="0mm" position="absolute"  reference-orientation="270">
...
            <fo:block-container height="29.7cm" width="21cm" top="0mm" left="0mm" position="absolute" reference-orientation="270">
...
            <fo:block-container height="29.7cm" width="21cm" top="210mm" left="0mm" position="absolute"  reference-orientation="270">

and if you have more than two pages don't forget to insert the

            <fo:block-container>
                <fo:block font-size="0.1pt" page-break-after="always" break-after="page"> </fo:block>
            </fo:block-container>

everywhere inbetween (after every second image)

Stefan Hegny
  • 2,107
  • 4
  • 23
  • 26