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 class
PdfBoxRenderer.NullUserInterface
-
Field Summary
Fields Modifier and Type Field Description private byte[]
_colorProfile
private byte
_defaultTextDirection
private org.w3c.dom.Document
_doc
private java.util.List<FSDOMMutator>
_domMutators
private float
_dotsPerPoint
private int
_initialPageNumber
private PDFCreationListener
_listener
private SVGDrawer
_mathmlImpl
private java.io.OutputStream
_os
private PdfBoxOutputDevice
_outputDevice
private PageSupplier
_pageSupplier
private PdfRendererBuilder.PdfAConformance
_pdfAConformance
private org.apache.pdfbox.pdmodel.PDDocument
_pdfDoc
private org.apache.pdfbox.pdmodel.encryption.PDEncryption
_pdfEncryption
private boolean
_pdfUaConformance
private float
_pdfVersion
private java.lang.String
_producer
private BidiReorderer
_reorderer
private BlockBox
_root
private SharedContext
_sharedContext
private BidiSplitterFactory
_splitterFactory
private SVGDrawer
_svgImpl
private boolean
_testMode
private boolean
_useFastMode
private static int
DEFAULT_DOTS_PER_PIXEL
private static float
DEFAULT_DOTS_PER_POINT
private static int
DEFAULT_PDF_POINTS_PER_INCH
private java.io.Closeable
diagnosticConsumer
private java.util.Comparator<PagePosition<?>>
PAGE_POSITION_COMPARATOR
Start 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 void
addPdfASchema(org.apache.pdfbox.pdmodel.PDDocument document, PdfRendererBuilder.PdfAConformance pdfAConformance, boolean isPdfUa)
void
cleanup()
Deprecated.Use close instead.void
close()
Cleanup thread resources.private <T> PagePosition<T>
createPagePosition(java.lang.String id, T element, int pageNo, float x, float y, float w, float h)
void
createPDF()
Creates a PDF with setup specified by builder.void
createPDF(java.io.OutputStream os)
Deprecated.Use builder to set output stream.void
createPDF(java.io.OutputStream os, boolean finish)
Deprecated.Use builder to set output stream.void
createPDF(java.io.OutputStream os, boolean finish, int initialPageNo)
Deprecated.Use builder to set output stream.private org.apache.xmpbox.schema.XMPSchema
createPdfaProperty(java.lang.String category, java.lang.String description, java.lang.String name, java.lang.String valueType)
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)
private void
createPdfFast(boolean finish, int initialPageNo)
Go fast!void
createPDFWithoutClosing()
Creates a PDF with setup specified by builder.private java.lang.String
createXPacket(java.lang.String metadata)
void
exportText(java.io.Writer writer)
Deprecated.unused and untested.private int
findEndPage(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 int
findStartPage(RenderingContext c, Layer layer, java.util.List<PageBox> pages)
Returns the start page for a layer.void
finishPDF()
Deprecated.private void
fireOnClose()
private void
firePreOpen()
private void
firePreWrite(int pageCount)
org.w3c.dom.Document
getDocument()
float
getDotsPerPoint()
private static org.w3c.dom.Element
getFirstChildElement(org.w3c.dom.Element element)
PdfBoxFontResolver
getFontResolver()
Get the PDF-BOX font resolver.private java.awt.Rectangle
getInitialExtents(LayoutContext c)
float
getLastContentBottom()
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.PDFCreationListener
getListener()
PdfBoxOutputDevice
getOutputDevice()
org.apache.pdfbox.pdmodel.PDDocument
getPdfDocument()
Returns the PDDocument or null if it has been closed.float
getPDFVersion()
BlockBox
getRootBox()
SharedContext
getSharedContext()
void
layout()
private org.w3c.dom.Document
loadDocument(java.lang.String uri)
private LayoutContext
newLayoutContext()
private RenderingContext
newRenderingContext()
private void
paintPage(RenderingContext c, PageBox page)
private void
paintPageFast(RenderingContext c, PageBox page, DisplayListContainer.DisplayListPageContainer pageOperations, int additionalTranslateX)
org.apache.pdfbox.pdmodel.PDPage
requestPage(org.apache.pdfbox.pdmodel.PDDocument doc, float pageWidth, float pageHeight, int pageNumber, int shadowPageNumber)
Called whenever a page or shadow-page is needed.private void
setDidValues(org.apache.pdfbox.pdmodel.PDDocument doc)
private void
setDocumentFromStringP(java.lang.String content, java.lang.String baseUrl)
private void
setDocumentP(java.io.File file)
private void
setDocumentP(java.lang.String uri)
private void
setDocumentP(org.w3c.dom.Document doc, java.lang.String url)
private void
setDocumentP(org.w3c.dom.Document doc, java.lang.String url, NamespaceHandler nsh)
void
setListener(PDFCreationListener listener)
private java.lang.String
stringfyMetadata(org.w3c.dom.Element element)
void
writeNextDocument()
Deprecated.Doubt this still works as untested.void
writeNextDocument(int initialPageNo)
Deprecated.Doubt this still works as untested.private void
writePDF(java.util.List<PageBox> pages, RenderingContext c, java.awt.geom.Rectangle2D firstPageSize, org.apache.pdfbox.pdmodel.PDDocument doc)
private void
writePDFFast(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.IOException
Creates 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.IOException
Creates 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.IOException
Deprecated.Use builder to set output stream.- Parameters:
os
-- Throws:
java.io.IOException
-
writeNextDocument
@Deprecated public void writeNextDocument() throws java.io.IOException
Deprecated.Doubt this still works as untested.- Throws:
java.io.IOException
-
writeNextDocument
@Deprecated public void writeNextDocument(int initialPageNo) throws java.io.IOException
Deprecated.Doubt this still works as untested.- Throws:
java.io.IOException
-
finishPDF
@Deprecated public void finishPDF() throws java.io.IOException
Deprecated.- Throws:
java.io.IOException
-
createPDF
@Deprecated public void createPDF(java.io.OutputStream os, boolean finish) throws java.io.IOException
Deprecated.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.IOException
Deprecated.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.IOException
Go 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.IOException
Deprecated.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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in 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:PageSupplier
Called whenever a page or shadow-page is needed.- Specified by:
requestPage
in interfacePageSupplier
- Parameters:
doc
-PDDocument
the 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.
-
-