Package org.xhtmlrenderer.simple
Class PDFRenderer
java.lang.Object
org.xhtmlrenderer.simple.PDFRenderer
PDFRenderer supports headless rendering of XHTML documents, outputting
to PDF format. There are two static utility methods, one for rendering
a URL, renderToPDF(String, String) and one
for rendering a File, renderToPDF(File, String)
You can use this utility from the command line by passing in the URL or file location as first parameter, and PDF path as second parameter:
java -cp %classpath% org.xhtmlrenderer.simple.PDFRenderer
- Author:
- Pete Brant, Patrick Wright
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidRenders a file or URL to a PDF.static voidrenderToPDF(byte[] bytes, String pdf) Renders the XML file as a PDF file at the target location.static voidrenderToPDF(byte[] bytes, String pdf, Character pdfVersion) Renders the XML file as a PDF file at the target location.static voidrenderToPDF(File file, String pdf) Renders the XML file as a PDF file at the target location.static voidrenderToPDF(File file, String pdf, Character pdfVersion) Renders the XML file as a PDF file at the target location.static voidrenderToPDF(String url, String pdf) Renders the XML file at the given URL as a PDF file at the target location.static voidrenderToPDF(String url, String pdf, Character pdfVersion) Renders the XML file at the given URL as a PDF file at the target location.static byte[]renderToPDFBytes(byte[] bytes) Renders the XML file as a PDF file and return its bytes.static byte[]renderToPDFBytes(byte[] bytes, Character pdfVersion) Renders the XML file as a PDF file return its bytes.
-
Constructor Details
-
PDFRenderer
public PDFRenderer()
-
-
Method Details
-
renderToPDF
public static void renderToPDF(String url, String pdf) throws IOException, com.itextpdf.text.DocumentException Renders the XML file at the given URL as a PDF file at the target location.- Parameters:
url- url for the XML file to renderpdf- path to the PDF file to create- Throws:
IOException- if the URL or PDF location is invalidcom.itextpdf.text.DocumentException- if an error occurred while building the Document.
-
renderToPDF
public static void renderToPDF(String url, String pdf, @Nullable Character pdfVersion) throws IOException, com.itextpdf.text.DocumentException Renders the XML file at the given URL as a PDF file at the target location.- Parameters:
url- url for the XML file to renderpdf- path to the PDF file to createpdfVersion- version of PDF to output; null uses default version- Throws:
IOException- if the URL or PDF location is invalidcom.itextpdf.text.DocumentException- if an error occurred while building the Document.
-
renderToPDF
public static void renderToPDF(File file, String pdf) throws IOException, com.itextpdf.text.DocumentException Renders the XML file as a PDF file at the target location.- Parameters:
file- XML file to renderpdf- path to the PDF file to create- Throws:
IOException- if the file or PDF location is invalidcom.itextpdf.text.DocumentException- if an error occurred while building the Document.
-
renderToPDF
public static void renderToPDF(File file, String pdf, @Nullable Character pdfVersion) throws IOException, com.itextpdf.text.DocumentException Renders the XML file as a PDF file at the target location.- Parameters:
file- XML file to renderpdf- path to the PDF file to createpdfVersion- version of PDF to output; null uses default version- Throws:
IOException- if the file or PDF location is invalidcom.itextpdf.text.DocumentException- if an error occurred while building the Document.
-
renderToPDFBytes
@Nonnull @CheckReturnValue public static byte[] renderToPDFBytes(byte[] bytes) throws IOException, com.itextpdf.text.DocumentException Renders the XML file as a PDF file and return its bytes.- Parameters:
bytes- XML file bytes to render- Throws:
IOException- if the file or PDF location is invalidcom.itextpdf.text.DocumentException- if an error occurred while building the Document.
-
renderToPDFBytes
@Nonnull @CheckReturnValue public static byte[] renderToPDFBytes(byte[] bytes, @Nullable Character pdfVersion) throws IOException, com.itextpdf.text.DocumentException Renders the XML file as a PDF file return its bytes.- Parameters:
bytes- XML file bytes to renderpdfVersion- version of PDF to output; null uses default version- Throws:
IOException- if the file or PDF location is invalidcom.itextpdf.text.DocumentException- if an error occurred while building the Document.
-
renderToPDF
public static void renderToPDF(byte[] bytes, String pdf) throws IOException, com.itextpdf.text.DocumentException Renders the XML file as a PDF file at the target location.- Parameters:
bytes- XML file bytes to renderpdf- path to the PDF file to create- Throws:
IOException- if the file or PDF location is invalidcom.itextpdf.text.DocumentException- if an error occurred while building the Document.
-
renderToPDF
public static void renderToPDF(byte[] bytes, String pdf, @Nullable Character pdfVersion) throws IOException, com.itextpdf.text.DocumentException Renders the XML file as a PDF file at the target location.- Parameters:
bytes- XML file bytes to renderpdf- path to the PDF file to createpdfVersion- version of PDF to output; null uses default version- Throws:
IOException- if the file or PDF location is invalidcom.itextpdf.text.DocumentException- if an error occurred while building the Document.
-
main
Renders a file or URL to a PDF. Command line use: first argument is URL or file path, second argument is path to PDF file to generate.- Parameters:
args- see desc- Throws:
IOException- if source could not be read, or if PDF path is invalidcom.itextpdf.text.DocumentException- if an error occurs while building the document
-