Class PdfBoxRenderer

  • All Implemented Interfaces:
    PageSupplier, java.io.Closeable, java.lang.AutoCloseable

    public class PdfBoxRenderer
    extends java.lang.Object
    implements java.io.Closeable, PageSupplier
    • 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
      • _domMutators

        private final java.util.List<FSDOMMutator> _domMutators
      • _doc

        private org.w3c.dom.Document _doc
      • _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
      • _pdfUaConformance

        private boolean _pdfUaConformance
      • _colorProfile

        private byte[] _colorProfile
      • _testMode

        private boolean _testMode
      • _os

        private java.io.OutputStream _os
      • _defaultTextDirection

        private byte _defaultTextDirection
      • _useFastMode

        private final boolean _useFastMode
      • 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.
    • 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)
      • 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
      • 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)
      • 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)
      • 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)
      • 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 interface java.lang.AutoCloseable
        Specified by:
        close in interface java.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 interface PageSupplier
        Parameters:
        doc - PDDocument the page belongs to
        pageWidth - Width of page in PDF points (1/72 inch)
        pageHeight - Height of page in PDF points
        pageNumber - 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 to getLayersPositions() which will return page positions for all layers. WARNING: NOT transform aware. A transformed layer will return page positions that are not correct.
      • 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.