It is possible to convert a standalone SVG document directly into a simple page PDF document.
This is possible through the use of Batik's transcoder mechanism.
java org.apache.batik.apps.rasterizer.Main -m application/pdf document.svg
This will output the svg document as "document.pdf" containing a PDF rendering of
the SVG file.
It is also possible to specify the width and/or height of the PDF document on the command line with -w and -h or if you are using the transcoder api you can use the transcoding hints.
Currently the SVG image is drawn at the SVG document size and simply scaled in PDF to the new size. So the result may not be the best possible. For example if you have any images or effects it will draw them at the original resolution of the svg document. When this is viewed in the pdf it will have an incorrect resolution for the size of the pdf.
The size of the pdf file will also remain the same regardless of what size the page is.
For more information see Batik for
how transcoders work.
These are the relevant classes, found in the package org.apache.fop.svg :
- PDFGraphics2D
used for drawing onto a Graphics2D into an existing pdf document, used
internally to draw the svg.
- PDFDocumentGraphics2D
used to create a pdf document and inherits from PDFGraphics2D to do the
rest of the drawing. Used by the transcoder to create a standalone pdf
document from an svg. Can be used independantly the same as any Graphics2D.
- PDFTranscoder
used to transcode an svg document into a standalone pdf, via
PDFDocumentGraphics2D.