Package com.openhtmltopdf.pdfboxout
Class PdfBoxRenderer
java.lang.Object
com.openhtmltopdf.pdfboxout.PdfBoxRenderer
- All Implemented Interfaces:
PageSupplier,Closeable,AutoCloseable
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]private byteprivate Documentprivate final List<FSDOMMutator> private final floatprivate final intprivate PDFCreationListenerprivate SVGDrawerprivate OutputStreamprivate final PdfBoxOutputDeviceprivate PageSupplierprivate org.apache.pdfbox.pdmodel.PDDocumentprivate org.apache.pdfbox.pdmodel.encryption.PDEncryptionprivate booleanprivate floatprivate Stringprivate BidiReordererprivate BlockBoxprivate final SharedContextprivate BidiSplitterFactoryprivate SVGDrawerprivate booleanprivate final booleanprivate static final intprivate static final floatprivate static final intprivate final Closeableprivate final Comparator<PagePosition<?>> Start page to end page and then top to bottom on page. -
Constructor Summary
ConstructorsConstructorDescriptionPdfBoxRenderer(BaseDocument doc, UnicodeImplementation unicode, PageDimensions pageSize, PdfRendererBuilderState state, Closeable diagnosticConsumer) This method is constantly changing as options are added to the builder. -
Method Summary
Modifier and TypeMethodDescriptionprivate 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(String id, T element, int pageNo, float x, float y, float w, float h) voidCreates a PDF with setup specified by builder.voidDeprecated.Use builder to set output stream.voidcreatePDF(OutputStream os, boolean finish) Deprecated.Use builder to set output stream.voidcreatePDF(OutputStream os, boolean finish, int initialPageNo) Deprecated.Use builder to set output stream.private org.apache.xmpbox.schema.XMPSchemacreatePdfaProperty(String category, String description, String name, String valueType) private org.apache.xmpbox.schema.XMPSchemacreatePdfaSchema(String schema, String namespace, String prefix, List<org.apache.xmpbox.schema.XMPSchema> properties) private voidcreatePdfFast(boolean finish, int initialPageNo) Go fast!voidCreates a PDF with setup specified by builder.private StringcreateXPacket(String metadata) voidexportText(Writer writer) Deprecated.unused and untested.private intfindEndPage(RenderingContext c, Layer layer, List<PageBox> pages) Returns the end page number for a layer.findPagePositionsByID(Pattern pattern) private intfindStartPage(RenderingContext c, Layer layer, List<PageBox> pages) Returns the start page for a layer.voidDeprecated.private voidprivate voidprivate voidfirePreWrite(int pageCount) floatprivate static ElementgetFirstChildElement(Element element) Get the PDF-BOX font resolver.private RectanglefloatReturns the bottom Y postion in bottom-up PDF units on the last page of content.private List<PagePosition<Layer>> getLayerPagePositions(Layer layer, List<PageBox> pages, RenderingContext ctx) getLayerPositions(Layer layer) Returns a list of page positions for a single layer.Returns a list of page positions for all layers in the document.org.apache.pdfbox.pdmodel.PDDocumentReturns the PDDocument or null if it has been closed.floatvoidlayout()private DocumentloadDocument(String uri) private LayoutContextprivate RenderingContextprivate 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(String content, String baseUrl) private voidsetDocumentP(File file) private voidsetDocumentP(String uri) private voidsetDocumentP(Document doc, String url) private voidsetDocumentP(Document doc, String url, NamespaceHandler nsh) voidsetListener(PDFCreationListener listener) private StringstringfyMetadata(Element element) voidDeprecated.Doubt this still works as untested.voidwriteNextDocument(int initialPageNo) Deprecated.Doubt this still works as untested.private voidwritePDF(List<PageBox> pages, RenderingContext c, Rectangle2D firstPageSize, org.apache.pdfbox.pdmodel.PDDocument doc) private voidwritePDFFast(List<PageBox> pages, RenderingContext c, Rectangle2D firstPageSize, org.apache.pdfbox.pdmodel.PDDocument doc)
-
Field Details
-
DEFAULT_DOTS_PER_POINT
private static final float DEFAULT_DOTS_PER_POINT- See Also:
-
DEFAULT_DOTS_PER_PIXEL
private static final int DEFAULT_DOTS_PER_PIXEL- See Also:
-
DEFAULT_PDF_POINTS_PER_INCH
private static final int DEFAULT_PDF_POINTS_PER_INCH- See Also:
-
_outputDevice
-
_domMutators
-
_doc
-
_root
-
_dotsPerPoint
private final float _dotsPerPoint -
_pdfDoc
private org.apache.pdfbox.pdmodel.PDDocument _pdfDoc -
_pdfEncryption
private org.apache.pdfbox.pdmodel.encryption.PDEncryption _pdfEncryption -
_producer
-
_pdfVersion
private float _pdfVersion -
_pdfAConformance
-
_pdfUaConformance
private boolean _pdfUaConformance -
_colorProfile
private byte[] _colorProfile -
_testMode
private boolean _testMode -
_listener
-
_os
-
_svgImpl
-
_mathmlImpl
-
_splitterFactory
-
_defaultTextDirection
private byte _defaultTextDirection -
_reorderer
-
_useFastMode
private final boolean _useFastMode -
_pageSupplier
-
diagnosticConsumer
-
_initialPageNumber
private final int _initialPageNumber -
PAGE_POSITION_COMPARATOR
Start page to end page and then top to bottom on page.
-
-
Constructor Details
-
PdfBoxRenderer
PdfBoxRenderer(BaseDocument doc, UnicodeImplementation unicode, PageDimensions pageSize, PdfRendererBuilderState state, Closeable diagnosticConsumer) This method is constantly changing as options are added to the builder.
-
-
Method Details
-
getDocument
-
getPdfDocument
public org.apache.pdfbox.pdmodel.PDDocument getPdfDocument()Returns the PDDocument or null if it has been closed. -
getFontResolver
Get the PDF-BOX font resolver. Can be used to add fonts in code.- Returns:
-
loadDocument
-
setDocumentP
-
setDocumentP
-
setDocumentP
- Throws:
IOException
-
setDocumentFromStringP
-
setDocumentP
-
getPDFVersion
public float getPDFVersion() -
layout
public void layout() -
getInitialExtents
-
newRenderingContext
-
newLayoutContext
-
createPDF
Creates a PDF with setup specified by builder. On finsihing or failing, saves (if successful) and closes the PDF document.- Throws:
IOException
-
createPDFWithoutClosing
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:
IOException
-
createPDF
Deprecated.Use builder to set output stream.- Parameters:
os-- Throws:
IOException
-
writeNextDocument
Deprecated.Doubt this still works as untested.- Throws:
IOException
-
writeNextDocument
Deprecated.Doubt this still works as untested.- Throws:
IOException
-
finishPDF
Deprecated.- Throws:
IOException
-
createPDF
Deprecated.Use builder to set output stream.- Throws:
IOException
-
createPDF
@Deprecated public void createPDF(OutputStream os, boolean finish, int initialPageNo) throws IOException Deprecated.Use builder to set output stream. NOTE: Caller is responsible for cleaning up the OutputStream.- Throws:
IOException
-
createPdfFast
Go fast!- Throws:
IOException
-
firePreOpen
private void firePreOpen() -
firePreWrite
private void firePreWrite(int pageCount) -
fireOnClose
private void fireOnClose() -
writePDFFast
private void writePDFFast(List<PageBox> pages, RenderingContext c, Rectangle2D firstPageSize, org.apache.pdfbox.pdmodel.PDDocument doc) throws IOException - Throws:
IOException
-
writePDF
private void writePDF(List<PageBox> pages, RenderingContext c, Rectangle2D firstPageSize, org.apache.pdfbox.pdmodel.PDDocument doc) throws IOException - Throws:
IOException
-
addPdfASchema
private void addPdfASchema(org.apache.pdfbox.pdmodel.PDDocument document, PdfRendererBuilder.PdfAConformance pdfAConformance, boolean isPdfUa) -
createPdfaSchema
-
createPdfaProperty
-
setDidValues
private void setDidValues(org.apache.pdfbox.pdmodel.PDDocument doc) -
paintPageFast
private void paintPageFast(RenderingContext c, PageBox page, DisplayListContainer.DisplayListPageContainer pageOperations, int additionalTranslateX) -
paintPage
-
stringfyMetadata
-
getFirstChildElement
-
createXPacket
-
getOutputDevice
-
exportText
Deprecated.unused and untested.- Parameters:
writer-- Throws:
IOException
-
getRootBox
-
getDotsPerPoint
public float getDotsPerPoint() -
findPagePositionsByID
-
getListener
-
setListener
-
cleanup
Deprecated.Use close instead. -
close
public void close()Cleanup thread resources. MUST be called after finishing with the renderer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
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
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
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 List<PagePosition<Layer>> getLayerPagePositions(Layer layer, List<PageBox> pages, RenderingContext ctx) -
createPagePosition
private <T> PagePosition<T> createPagePosition(String id, T element, int pageNo, float x, float y, float w, float h) -
findStartPage
Returns the start page for a layer. Transform aware. -
findEndPage
Returns the end page number for a layer. Transform aware.
-