Class XHtmlMetaToPdfInfoAdapter
java.lang.Object
org.openpdf.pdf.DefaultPDFCreationListener
org.openpdf.pdf.util.XHtmlMetaToPdfInfoAdapter
- All Implemented Interfaces:
PDFCreationListener
Description
This PDF Creation Listener parses meta data elements from an (X)HTML document and appends them to the info dictionary of a PDF document.
The XHTML document is parsed for relevant PDF meta data during construction, then adds the meta data to the PDF document when the PDF document is closed by the calling ITextRenderer.
Valid (X)HTML tags are:
- TITLE
Valid (X)HTML meta tag attribute names are:
- TITLE (optional), DC.TITLE
- CREATOR, AUTHOR, DC.CREATOR
- SUBJECT, DC.SUBJECT
- KEYWORDS
Valid PDF meta names are defined in Adobe's PDF Reference (Sixth Edition), section "10.2.1 - Document Information Dictionary", table 10.2, pg.844 ...
Usage
// Setup output stream OutputStream outputStream = ... // Create W3C document model Document doc = ... // Create new PDF renderer ITextRenderer renderer = new ITextRenderer(); // Add PDF creation listener PDFCreationListener pdfCreationListener = new XHtmlMetaToPdfInfoAdapter( doc ); renderer.setListener( pdfCreationListener); // Add W3C document to renderer renderer.setDocument( doc, null ); // Layout PDF document renderer.layout(); // Write PDF document renderer.createPDF( outputStream, true );
Notes
This class was derived from a sample PDF creation listener at "http://markmail.org/message/46t3bw7q6mbhvra2" by Jesse Keller invalid input: '<'jesse.keller@roche.com>.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final String -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new adapter from the given XHTML document. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddPdfMetaValuesToPdfDocument(ITextRenderer renderer) Add PDF meta values to the target PDF document.voidonClose(ITextRenderer renderer) PDFCreationListener onClose event handler.private voidprivate voidparseHtmlTags(Document doc) private voidMethods inherited from class DefaultPDFCreationListener
preOpen, preWrite
-
Field Details
-
HTML_TAG_TITLE
- See Also:
-
HTML_TAG_HEAD
- See Also:
-
HTML_TAG_META
- See Also:
-
HTML_META_KEY_TITLE
- See Also:
-
HTML_META_KEY_DC_TITLE
- See Also:
-
HTML_META_KEY_CREATOR
- See Also:
-
HTML_META_KEY_DC_CREATOR
- See Also:
-
HTML_META_KEY_SUBJECT
- See Also:
-
HTML_META_KEY_DC_SUBJECT
- See Also:
-
HTML_META_KEY_KEYWORDS
- See Also:
-
HTML_META_ATTR_NAME
- See Also:
-
HTML_META_ATTR_CONTENT
- See Also:
-
pdfInfoValues
-
-
Constructor Details
-
XHtmlMetaToPdfInfoAdapter
Creates a new adapter from the given XHTML document.- Parameters:
doc- XHTML document
-
-
Method Details
-
onClose
PDFCreationListener onClose event handler.- Specified by:
onClosein interfacePDFCreationListener- Overrides:
onClosein classDefaultPDFCreationListener- Parameters:
renderer- the iTextRenderer preparing the document- See Also:
-
parseHtmlTags
-
parseHtmlTitleTag
-
parseHtmlMetaTags
-
addPdfMetaValuesToPdfDocument
Add PDF meta values to the target PDF document.
-