SVG To Multipage PDF

1.7k views Asked by At

I am trying to convert SVG to a multi page PDF document. I was using Apache Batik for the conversion, but there is no provision for multi page pdfs in it. After doing some research I got to know about docbook and it worked quite well. It uses ANT scripts for the conversion.

I wanted to know how the docbook is dealing with the multi page PDFs because docbook uses Apache FOP which uses Apache Batik for SVG to PDF conversion.

Does it create single PDF files and eventually combines them to make a single PDF? And if it is doing the same as above, then I myself will create single PDFs using Apache Batik and combine them using PDFBox.

Thanks.

Solution Using XSL-FO with SVG as external graphic or as embedded SVG

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <fo:layout-master-set>
    <fo:simple-page-master page-height="2339px" page-width="1654px" master-name="PageMaster">
        <fo:region-body margin="0mm 0mm 0mm 0mm"/>
    </fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="PageMaster">
    <fo:flow flow-name="xsl-region-body">
        <fo:block>
            <fo:external-graphic src="url(new sample.svg)" width="100%" height="100%" content-width="100%" content-height="100%"/>
        </fo:block>
    </fo:flow>
  </fo:page-sequence>
<fo:page-sequence master-reference="PageMaster">
    <fo:flow flow-name="xsl-region-body">
        <fo:block>
            <fo:external-graphic src="url(new sample2.svg)" width="100%" height="100%" content-width="100%" content-height="100%"/>
        </fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>
1

There are 1 answers

1
Kevin Brown On BEST ANSWER

No it is not. FOP is using the XSL FO standard. You define things like the page geometry, rules for keeping content together and flow content blocks into it. It is not creating each page as PDF and joining them. It only uses Batik to convert the SVG to PDF objects for inclusion in the PDF output. So Batik is only creating a "block" area ... like an image although in vector format ... and it is but one of the blocks used to flow into the page geometry.