public class XmlToPdf
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Class and Description |
---|---|
protected class |
XmlToPdf.PdfHeaderFooter
Inner class that adds a header and a footer to PDF document pages.
|
static class |
XmlToPdf.RomanNumber
Inner class that provides conversion of decimal integers to roman numerals.
|
protected class |
XmlToPdf.XmlCell
Inner class that defines a table cell node in the XML document and handles
translation of the XML table cell to a PDF table cell.
|
protected class |
XmlToPdf.XmlPage
Inner class that defines a page node in the XML document and handles
translation of the XML page to a PDF page.
|
protected class |
XmlToPdf.XmlTable
Inner class that defines a table node in the XML document and handles
translation of the XML table to a PDF table.
|
Modifier and Type | Field and Description |
---|---|
protected static int |
ALIGN_CENTER
The value for center aligning content.
|
protected static int |
ALIGN_LEFT
The value for left aligning content.
|
protected static int |
ALIGN_RIGHT
The value for right aligning content.
|
protected static java.lang.String |
FMT_FOOT
The formatter for page footer information.
|
protected static com.itextpdf.text.Font |
FONT_BOLD
The font for bold text.
|
protected static com.itextpdf.text.Font |
FONT_CVR_BOLD
The font for cover page bold text.
|
protected static com.itextpdf.text.Font |
FONT_CVR_NORM
The font for cover page normal text.
|
protected static com.itextpdf.text.Font |
FONT_DATA
The font for data text.
|
protected static com.itextpdf.text.Font |
FONT_FOOT
The font for footer text.
|
protected static com.itextpdf.text.Font |
FONT_HEAD
The font for header text.
|
protected static com.itextpdf.text.Font |
FONT_HIDE
The font for hidden text.
|
protected static com.itextpdf.text.Font |
FONT_NORM
The font for normal text.
|
protected static com.itextpdf.text.Font |
FONT_TOC_CHAPTER
The font for table of contents bold text.
|
protected static com.itextpdf.text.Font |
FONT_TOC_SECTION
The font for table of contents normal text.
|
protected java.util.ArrayList<com.itextpdf.text.Chapter> |
ivChapters
A collection of all chapters for the PDF document.
|
protected java.util.LinkedHashMap<com.itextpdf.text.Chunk,java.lang.Integer> |
ivLinks
A collection of links to the chapters and sections in the PDF document.
|
protected com.itextpdf.text.Document |
ivPdfDoc
The PDF document object.
|
protected org.w3c.dom.Document |
ivXmlDoc
The XML document object.
|
private static long |
serialVersionUID
The class' serialization version id.
|
protected static com.itextpdf.text.BaseColor |
TBLBORDER
The border color for gridlist tables.
|
protected static com.itextpdf.text.BaseColor |
TBLHEADBG
The background color for gridlist table headings.
|
Constructor and Description |
---|
XmlToPdf()
Constructs a new XML-to-PDF translator.
|
Modifier and Type | Method and Description |
---|---|
protected void |
createTOC()
Creates a table of contents based on chapter and section links created
while the PDF document was being created.
|
java.io.ByteArrayOutputStream |
getPdfStream(java.lang.String xml)
Performs XML-to-PDF translation and returns the results.
|
java.io.ByteArrayOutputStream |
getPdfStream(java.lang.String template,
org.apache.velocity.VelocityContext data)
Performs HTML-to-PDF translation and returns the results.
|
protected java.io.ByteArrayOutputStream |
moveTOC(java.io.ByteArrayOutputStream pdf,
int[] pagenums)
Moves a table of contents from the end of the PDF document to the beginning
of the document, starting at the first page following the cover page, if one
exists.
|
protected void |
recurseXml(org.w3c.dom.NodeList children)
Recurses the XML document and creates the PDF document's content.
|
protected java.io.ByteArrayOutputStream |
translate(java.lang.String xml)
Performs XML-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_CVR_BOLD
protected static final com.itextpdf.text.Font FONT_CVR_NORM
protected static final com.itextpdf.text.Font FONT_TOC_CHAPTER
protected static final com.itextpdf.text.Font FONT_TOC_SECTION
protected static final com.itextpdf.text.Font FONT_BOLD
protected static final com.itextpdf.text.Font FONT_NORM
protected static final com.itextpdf.text.Font FONT_HEAD
protected static final com.itextpdf.text.Font FONT_DATA
protected static final com.itextpdf.text.Font FONT_FOOT
protected static final com.itextpdf.text.Font FONT_HIDE
protected static final com.itextpdf.text.BaseColor TBLBORDER
protected static final com.itextpdf.text.BaseColor TBLHEADBG
protected static final int ALIGN_LEFT
protected static final int ALIGN_CENTER
protected static final int ALIGN_RIGHT
protected static final java.lang.String FMT_FOOT
protected com.itextpdf.text.Document ivPdfDoc
protected org.w3c.dom.Document ivXmlDoc
protected java.util.ArrayList<com.itextpdf.text.Chapter> ivChapters
protected java.util.LinkedHashMap<com.itextpdf.text.Chunk,java.lang.Integer> ivLinks
public java.io.ByteArrayOutputStream getPdfStream(java.lang.String xml) throws java.lang.Exception
xml
- (String) The XML to process.java.lang.Exception
- - if an error occurs during translation.public java.io.ByteArrayOutputStream getPdfStream(java.lang.String template, org.apache.velocity.VelocityContext data) throws java.lang.Exception
template
- (String) The name of the XML template file to process.data
- (VelocityContext) The data to use for substitutions or
null
if no data is to be substituted.java.lang.Exception
- - if an error occurs during translation.protected java.io.ByteArrayOutputStream translate(java.lang.String xml) throws java.lang.Exception
xml
- (ByteArrayOutputStream) The XML to process.java.lang.Exception
- - if an error occurs during translation.protected void createTOC() throws java.lang.Exception
java.lang.Exception
- - if an error occurs during processing.protected java.io.ByteArrayOutputStream moveTOC(java.io.ByteArrayOutputStream pdf, int[] pagenums) throws java.lang.Exception
pdf
- (ByteArrayOutputStream) The PDF document to process.pagenums
- (int[]) The documents various page numbers as returned
by PdfHeaderFooter.getPageNumbers
.java.lang.Exception
- - if an error occurs during processing.protected void recurseXml(org.w3c.dom.NodeList children) throws java.lang.Exception
children
- (NodeList) The first-level child nodes of the XML
document's root.java.lang.Exception
- - if an error occurs during processing.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.