Package com.openhtmltopdf.pdfboxout
Class PdfBoxRenderer
- java.lang.Object
-
- com.openhtmltopdf.pdfboxout.PdfBoxRenderer
-
- All Implemented Interfaces:
PageSupplier,java.io.Closeable,java.lang.AutoCloseable
public class PdfBoxRenderer extends java.lang.Object implements java.io.Closeable, PageSupplier
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classPdfBoxRenderer.NullUserInterface
-
Field Summary
Fields Modifier and Type Field Description private byte[]_colorProfileprivate byte_defaultTextDirectionprivate org.w3c.dom.Document_docprivate java.util.List<FSDOMMutator>_domMutatorsprivate float_dotsPerPointprivate int_initialPageNumberprivate PDFCreationListener_listenerprivate SVGDrawer_mathmlImplprivate java.io.OutputStream_osprivate PdfBoxOutputDevice_outputDeviceprivate PageSupplier_pageSupplierprivate PdfRendererBuilder.PdfAConformance_pdfAConformanceprivate org.apache.pdfbox.pdmodel.PDDocument_pdfDocprivate org.apache.pdfbox.pdmodel.encryption.PDEncryption_pdfEncryptionprivate boolean_pdfUaConformanceprivate float_pdfVersionprivate java.lang.String_producerprivate BidiReorderer_reordererprivate BlockBox_rootprivate SharedContext_sharedContextprivate BidiSplitterFactory_splitterFactoryprivate SVGDrawer_svgImplprivate boolean_testModeprivate boolean_useFastModeprivate static intDEFAULT_DOTS_PER_PIXELprivate static floatDEFAULT_DOTS_PER_POINTprivate static intDEFAULT_PDF_POINTS_PER_INCHprivate java.io.CloseablediagnosticConsumerprivate java.util.Comparator<PagePosition<?>>PAGE_POSITION_COMPARATORStart page to end page and then top to bottom on page.
-
Constructor Summary
Constructors Constructor Description PdfBoxRenderer(BaseDocument doc, UnicodeImplementation unicode, PageDimensions pageSize, PdfRendererBuilderState state, java.io.Closeable diagnosticConsumer)This method is constantly changing as options are added to the builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private voidaddPdfASchema(org.apache.pdfbox.pdmodel.PDDocument document, PdfRendererBuilder.PdfAConformance pdfAConformance, boolean isPdfUa)voidcleanup()Deprecated.Use close instead.voidclose()Cleanup thread resources.private <T> PagePosition<T>createPagePosition(java.lang.String id, T element, int pageNo, float x, float y, float w, float h)voidcreatePDF()Creates a PDF with setup specified by builder.voidcreatePDF(java.io.OutputStream os)Deprecated.Use builder to set output stream.voidcreatePDF(java.io.OutputStream os, boolean finish)Deprecated.Use builder to set output stream.voidcreatePDF(java.io.OutputStream os, boolean finish, int initialPageNo)Deprecated.Use builder to set output stream.private org.apache.xmpbox.schema.XMPSchemacreatePdfaProperty(java.lang.String category, java.lang.String description, java.lang.String name, java.lang.String valueType)private org.apache.xmpbox.schema.XMPSchemacreatePdfaSchema(java.lang.String schema, java.lang.String namespace, java.lang.String prefix, java.util.List<org.apache.xmpbox.schema.XMPSchema> properties)private voidcreatePdfFast(boolean finish, int initialPageNo)Go fast!voidcreatePDFWithoutClosing()Creates a PDF with setup specified by builder.private java.lang.StringcreateXPacket(java.lang.String metadata)voidexportText(java.io.Writer writer)Deprecated.unused and untested.private intfindEndPage(RenderingContext c, Layer layer, java.util.List<PageBox> pages)Returns the end page number for a layer.java.util.List<PagePosition<Box>>findPagePositionsByID(java.util.regex.Pattern pattern)private intfindStartPage(RenderingContext c, Layer layer, java.util.List<PageBox> pages)Returns the start page for a layer.voidfinishPDF()Deprecated.private voidfireOnClose()private voidfirePreOpen()private voidfirePreWrite(int pageCount)org.w3c.dom.DocumentgetDocument()floatgetDotsPerPoint()private static org.w3c.dom.ElementgetFirstChildElement(org.w3c.dom.Element element)PdfBoxFontResolvergetFontResolver()Get the PDF-BOX font resolver.private java.awt.RectanglegetInitialExtents(LayoutContext c)floatgetLastContentBottom()Returns the bottom Y postion in bottom-up PDF units on the last page of content.private java.util.List<PagePosition<Layer>>getLayerPagePositions(Layer layer, java.util.List<PageBox> pages, RenderingContext ctx)java.util.List<PagePosition<Layer>>getLayerPositions(Layer layer)Returns a list of page positions for a single layer.java.util.List<PagePosition<Layer>>getLayersPositions()Returns a list of page positions for all layers in the document.PDFCreationListenergetListener()PdfBoxOutputDevicegetOutputDevice()org.apache.pdfbox.pdmodel.PDDocumentgetPdfDocument()Returns the PDDocument or null if it has been closed.floatgetPDFVersion()BlockBoxgetRootBox()SharedContextgetSharedContext()voidlayout()private org.w3c.dom.DocumentloadDocument(java.lang.String uri)private LayoutContextnewLayoutContext()private RenderingContextnewRenderingContext()private voidpaintPage(RenderingContext c, PageBox page)private voidpaintPageFast(RenderingContext c, PageBox page, DisplayListContainer.DisplayListPageContainer pageOperations, int additionalTranslateX)org.apache.pdfbox.pdmodel.PDPagerequestPage(org.apache.pdfbox.pdmodel.PDDocument doc, float pageWidth, float pageHeight, int pageNumber, int shadowPageNumber)Called whenever a page or shadow-page is needed.private voidsetDidValues(org.apache.pdfbox.pdmodel.PDDocument doc)private voidsetDocumentFromStringP(java.lang.String content, java.lang.String baseUrl)private voidsetDocumentP(java.io.File file)private voidsetDocumentP(java.lang.String uri)private voidsetDocumentP(org.w3c.dom.Document doc, java.lang.String url)private voidsetDocumentP(org.w3c.dom.Document doc, java.lang.String url, NamespaceHandler nsh)voidsetListener(PDFCreationListener listener)private java.lang.StringstringfyMetadata(org.w3c.dom.Element element)voidwriteNextDocument()Deprecated.Doubt this still works as untested.voidwriteNextDocument(int initialPageNo)Deprecated.Doubt this still works as untested.private voidwritePDF(java.util.List<PageBox> pages, RenderingContext c, java.awt.geom.Rectangle2D firstPageSize, org.apache.pdfbox.pdmodel.PDDocument doc)private voidwritePDFFast(java.util.List<PageBox> pages, RenderingContext c, java.awt.geom.Rectangle2D firstPageSize, org.apache.pdfbox.pdmodel.PDDocument doc)
-
-
-
Field Detail
-
DEFAULT_DOTS_PER_POINT
private static final float DEFAULT_DOTS_PER_POINT
- See Also:
- Constant Field Values
-
DEFAULT_DOTS_PER_PIXEL
private static final int DEFAULT_DOTS_PER_PIXEL
- See Also:
- Constant Field Values
-
DEFAULT_PDF_POINTS_PER_INCH
private static final int DEFAULT_PDF_POINTS_PER_INCH
- See Also:
- Constant Field Values
-
_sharedContext
private final SharedContext _sharedContext
-
_outputDevice
private final PdfBoxOutputDevice _outputDevice
-
_domMutators
private final java.util.List<FSDOMMutator> _domMutators
-
_doc
private org.w3c.dom.Document _doc
-
_root
private BlockBox _root
-
_dotsPerPoint
private final float _dotsPerPoint
-
_pdfDoc
private org.apache.pdfbox.pdmodel.PDDocument _pdfDoc
-
_pdfEncryption
private org.apache.pdfbox.pdmodel.encryption.PDEncryption _pdfEncryption
-
_producer
private java.lang.String _producer
-
_pdfVersion
private float _pdfVersion
-
_pdfAConformance
private PdfRendererBuilder.PdfAConformance _pdfAConformance
-
_pdfUaConformance
private boolean _pdfUaConformance
-
_colorProfile
private byte[] _colorProfile
-
_testMode
private boolean _testMode
-
_listener
private PDFCreationListener _listener
-
_os
private java.io.OutputStream _os
-
_svgImpl
private SVGDrawer _svgImpl
-
_mathmlImpl
private SVGDrawer _mathmlImpl
-
_splitterFactory
private BidiSplitterFactory _splitterFactory
-
_defaultTextDirection
private byte _defaultTextDirection
-
_reorderer
private BidiReorderer _reorderer
-
_useFastMode
private final boolean _useFastMode
-
_pageSupplier
private PageSupplier _pageSupplier
-
diagnosticConsumer
private final java.io.Closeable diagnosticConsumer
-
_initialPageNumber
private final int _initialPageNumber
-
PAGE_POSITION_COMPARATOR
private final java.util.Comparator<PagePosition<?>> PAGE_POSITION_COMPARATOR
Start page to end page and then top to bottom on page.
-
-
Constructor Detail
-
PdfBoxRenderer
PdfBoxRenderer(BaseDocument doc, UnicodeImplementation unicode, PageDimensions pageSize, PdfRendererBuilderState state, java.io.Closeable diagnosticConsumer)
This method is constantly changing as options are added to the builder.
-
-
Method Detail
-
getDocument
public org.w3c.dom.Document getDocument()
-
getPdfDocument
public org.apache.pdfbox.pdmodel.PDDocument getPdfDocument()
Returns the PDDocument or null if it has been closed.
-
getFontResolver
public PdfBoxFontResolver getFontResolver()
Get the PDF-BOX font resolver. Can be used to add fonts in code.- Returns:
-
loadDocument
private org.w3c.dom.Document loadDocument(java.lang.String uri)
-
setDocumentP
private void setDocumentP(java.lang.String uri)
-
setDocumentP
private void setDocumentP(org.w3c.dom.Document doc, java.lang.String url)
-
setDocumentP
private void setDocumentP(java.io.File file) throws java.io.IOException- Throws:
java.io.IOException
-
setDocumentFromStringP
private void setDocumentFromStringP(java.lang.String content, java.lang.String baseUrl)
-
setDocumentP
private void setDocumentP(org.w3c.dom.Document doc, java.lang.String url, NamespaceHandler nsh)
-
getPDFVersion
public float getPDFVersion()
-
layout
public void layout()
-
getInitialExtents
private java.awt.Rectangle getInitialExtents(LayoutContext c)
-
newRenderingContext
private RenderingContext newRenderingContext()
-
newLayoutContext
private LayoutContext newLayoutContext()
-
createPDF
public void createPDF() throws java.io.IOExceptionCreates a PDF with setup specified by builder. On finsihing or failing, saves (if successful) and closes the PDF document.- Throws:
java.io.IOException
-
createPDFWithoutClosing
public void createPDFWithoutClosing() throws java.io.IOExceptionCreates a PDF with setup specified by builder. On finsihing or failing, DOES NOT save or close the PDF document. Useful for post-processing the PDDocument which can be retrieved by getPdfDocument().- Throws:
java.io.IOException
-
createPDF
@Deprecated public void createPDF(java.io.OutputStream os) throws java.io.IOExceptionDeprecated.Use builder to set output stream.- Parameters:
os-- Throws:
java.io.IOException
-
writeNextDocument
@Deprecated public void writeNextDocument() throws java.io.IOExceptionDeprecated.Doubt this still works as untested.- Throws:
java.io.IOException
-
writeNextDocument
@Deprecated public void writeNextDocument(int initialPageNo) throws java.io.IOExceptionDeprecated.Doubt this still works as untested.- Throws:
java.io.IOException
-
finishPDF
@Deprecated public void finishPDF() throws java.io.IOExceptionDeprecated.- Throws:
java.io.IOException
-
createPDF
@Deprecated public void createPDF(java.io.OutputStream os, boolean finish) throws java.io.IOExceptionDeprecated.Use builder to set output stream.- Throws:
java.io.IOException
-
createPDF
@Deprecated public void createPDF(java.io.OutputStream os, boolean finish, int initialPageNo) throws java.io.IOExceptionDeprecated.Use builder to set output stream. NOTE: Caller is responsible for cleaning up the OutputStream.- Throws:
java.io.IOException
-
createPdfFast
private void createPdfFast(boolean finish, int initialPageNo) throws java.io.IOExceptionGo fast!- Throws:
java.io.IOException
-
firePreOpen
private void firePreOpen()
-
firePreWrite
private void firePreWrite(int pageCount)
-
fireOnClose
private void fireOnClose()
-
writePDFFast
private void writePDFFast(java.util.List<PageBox> pages, RenderingContext c, java.awt.geom.Rectangle2D firstPageSize, org.apache.pdfbox.pdmodel.PDDocument doc) throws java.io.IOException
- Throws:
java.io.IOException
-
writePDF
private void writePDF(java.util.List<PageBox> pages, RenderingContext c, java.awt.geom.Rectangle2D firstPageSize, org.apache.pdfbox.pdmodel.PDDocument doc) throws java.io.IOException
- Throws:
java.io.IOException
-
addPdfASchema
private void addPdfASchema(org.apache.pdfbox.pdmodel.PDDocument document, PdfRendererBuilder.PdfAConformance pdfAConformance, boolean isPdfUa)
-
createPdfaSchema
private org.apache.xmpbox.schema.XMPSchema createPdfaSchema(java.lang.String schema, java.lang.String namespace, java.lang.String prefix, java.util.List<org.apache.xmpbox.schema.XMPSchema> properties)
-
createPdfaProperty
private org.apache.xmpbox.schema.XMPSchema createPdfaProperty(java.lang.String category, java.lang.String description, java.lang.String name, java.lang.String valueType)
-
setDidValues
private void setDidValues(org.apache.pdfbox.pdmodel.PDDocument doc)
-
paintPageFast
private void paintPageFast(RenderingContext c, PageBox page, DisplayListContainer.DisplayListPageContainer pageOperations, int additionalTranslateX)
-
paintPage
private void paintPage(RenderingContext c, PageBox page)
-
stringfyMetadata
private java.lang.String stringfyMetadata(org.w3c.dom.Element element)
-
getFirstChildElement
private static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Element element)
-
createXPacket
private java.lang.String createXPacket(java.lang.String metadata)
-
getOutputDevice
public PdfBoxOutputDevice getOutputDevice()
-
getSharedContext
public SharedContext getSharedContext()
-
exportText
@Deprecated public void exportText(java.io.Writer writer) throws java.io.IOExceptionDeprecated.unused and untested.- Parameters:
writer-- Throws:
java.io.IOException
-
getRootBox
public BlockBox getRootBox()
-
getDotsPerPoint
public float getDotsPerPoint()
-
findPagePositionsByID
public java.util.List<PagePosition<Box>> findPagePositionsByID(java.util.regex.Pattern pattern)
-
getListener
public PDFCreationListener getListener()
-
setListener
public void setListener(PDFCreationListener listener)
-
cleanup
@Deprecated public void cleanup()
Deprecated.Use close instead.
-
close
public void close()
Cleanup thread resources. MUST be called after finishing with the renderer.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
requestPage
public org.apache.pdfbox.pdmodel.PDPage requestPage(org.apache.pdfbox.pdmodel.PDDocument doc, float pageWidth, float pageHeight, int pageNumber, int shadowPageNumber)Description copied from interface:PageSupplierCalled whenever a page or shadow-page is needed.- Specified by:
requestPagein interfacePageSupplier- Parameters:
doc-PDDocumentthe page belongs topageWidth- Width of page in PDF points (1/72 inch)pageHeight- Height of page in PDF pointspageNumber- Number of the layout page - this may differ from the PDF document page if there are previous shadow pages.shadowPageNumber- Number of the shadow-page or -1 if on a main page.- Returns:
PDPage
-
getLastContentBottom
public float getLastContentBottom()
Returns the bottom Y postion in bottom-up PDF units on the last page of content. WARNING: NOT transform aware.
-
getLayersPositions
public java.util.List<PagePosition<Layer>> getLayersPositions()
Returns a list of page positions for all layers in the document. The page positions are sorted from first page to last and then top to bottom. The page position values are in bottom-up PDF units. WARNING: NOT transform aware. Transformed layers will return page positions that are not correct.
-
getLayerPositions
public java.util.List<PagePosition<Layer>> getLayerPositions(Layer layer)
Returns a list of page positions for a single layer. The page positions are sorted from first page to last and then top to bottom. The page position values are in bottom-up PDF units. Compare togetLayersPositions()which will return page positions for all layers. WARNING: NOT transform aware. A transformed layer will return page positions that are not correct.
-
getLayerPagePositions
private java.util.List<PagePosition<Layer>> getLayerPagePositions(Layer layer, java.util.List<PageBox> pages, RenderingContext ctx)
-
createPagePosition
private <T> PagePosition<T> createPagePosition(java.lang.String id, T element, int pageNo, float x, float y, float w, float h)
-
findStartPage
private int findStartPage(RenderingContext c, Layer layer, java.util.List<PageBox> pages)
Returns the start page for a layer. Transform aware.
-
findEndPage
private int findEndPage(RenderingContext c, Layer layer, java.util.List<PageBox> pages)
Returns the end page number for a layer. Transform aware.
-
-