public class HtmlToPdf
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Class and Description |
---|---|
protected class |
HtmlToPdf.HeaderFooter
Inner class that adds a header and a footer to PDF document pages.
|
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
FMT_FOOT
The formatter for page footer information.
|
protected static com.itextpdf.text.Font |
FONT_FOOT
The font used for page footers.
|
protected static com.itextpdf.text.Font |
FONT_HEAD
The font used for page headers.
|
private static long |
serialVersionUID
The class' serialization version id.
|
Constructor and Description |
---|
HtmlToPdf()
Constructs a new HTML-to-PDF translator.
|
Modifier and Type | Method and Description |
---|---|
java.io.ByteArrayOutputStream |
getPdfStream(java.lang.String html,
boolean rotate)
Performs HTML-to-PDF translation and returns the results.
|
java.io.ByteArrayOutputStream |
getPdfStream(java.lang.String template,
org.apache.velocity.VelocityContext data,
boolean rotate)
Performs HTML-to-PDF translation and returns the results.
|
protected java.io.ByteArrayOutputStream |
translate(java.io.ByteArrayOutputStream xhtml,
boolean rotate)
Performs XHTML-to-PDF translation and returns the results.
|
void |
writeToResponse(java.io.ByteArrayOutputStream pdf,
javax.servlet.http.HttpServletResponse response)
Writes a PDF document to a servlet's outgoing response.
|
private static final long serialVersionUID
protected static final com.itextpdf.text.Font FONT_HEAD
protected static final com.itextpdf.text.Font FONT_FOOT
protected static final java.lang.String FMT_FOOT
public java.io.ByteArrayOutputStream getPdfStream(java.lang.String html, boolean rotate) throws java.lang.Exception
html
- (String) The HTML to process.rotate
- (boolean) true
to create the PDF document with
landscape orientation (rotated) or false
to create the
PDF document with portrait orientation (not rotated).java.lang.Exception
- - if an error occurs during translation.public java.io.ByteArrayOutputStream getPdfStream(java.lang.String template, org.apache.velocity.VelocityContext data, boolean rotate) throws java.lang.Exception
template
- (String) The name of the HTML template file to process.data
- (VelocityContext) The data to use for substitutions or
null
if no data is to be substituted.rotate
- (boolean) true
to create the PDF document with
landscape orientation (rotated) or false
to create the
PDF document with portrait orientation (not rotated).java.lang.Exception
- - if an error occurs during translation.protected java.io.ByteArrayOutputStream translate(java.io.ByteArrayOutputStream xhtml, boolean rotate) throws java.lang.Exception
xhtml
- (ByteArrayOutputStream) The XHTML to process.rotate
- (boolean) true
to create the PDF document with
landscape orientation (rotated) or false
to create the
PDF document with portrait orientation (not rotated).java.lang.Exception
- - if an error occurs during translation.public void writeToResponse(java.io.ByteArrayOutputStream pdf, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception
pdf
- (ByteArrayOutputStream) The PDF document to write.response
- (HttpServletResponse) The servlet response to write to.java.lang.Exception
- - if an error occurs during the writing.