Class PdfBoxRenderer

java.lang.Object
com.openhtmltopdf.pdfboxout.PdfBoxRenderer
All Implemented Interfaces:
PageSupplier, Closeable, AutoCloseable

public class PdfBoxRenderer extends Object implements Closeable, PageSupplier
  • 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:
    • _sharedContext

      private final SharedContext _sharedContext
    • _outputDevice

      private final PdfBoxOutputDevice _outputDevice
    • _domMutators

      private final List<FSDOMMutator> _domMutators
    • _doc

      private 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 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 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 Closeable diagnosticConsumer
    • _initialPageNumber

      private final int _initialPageNumber
    • PAGE_POSITION_COMPARATOR

      private final Comparator<PagePosition<?>> PAGE_POSITION_COMPARATOR
      Start page to end page and then top to bottom on page.
  • Constructor Details

  • Method Details

    • getDocument

      public 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 Document loadDocument(String uri)
    • setDocumentP

      private void setDocumentP(String uri)
    • setDocumentP

      private void setDocumentP(Document doc, String url)
    • setDocumentP

      private void setDocumentP(File file) throws IOException
      Throws:
      IOException
    • setDocumentFromStringP

      private void setDocumentFromStringP(String content, String baseUrl)
    • setDocumentP

      private void setDocumentP(Document doc, String url, NamespaceHandler nsh)
    • getPDFVersion

      public float getPDFVersion()
    • layout

      public void layout()
    • getInitialExtents

      private Rectangle getInitialExtents(LayoutContext c)
    • newRenderingContext

      private RenderingContext newRenderingContext()
    • newLayoutContext

      private LayoutContext newLayoutContext()
    • createPDF

      public void createPDF() throws IOException
      Creates a PDF with setup specified by builder. On finsihing or failing, saves (if successful) and closes the PDF document.
      Throws:
      IOException
    • createPDFWithoutClosing

      public void createPDFWithoutClosing() throws 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:
      IOException
    • createPDF

      @Deprecated public void createPDF(OutputStream os) throws IOException
      Deprecated.
      Use builder to set output stream.
      Parameters:
      os -
      Throws:
      IOException
    • writeNextDocument

      @Deprecated public void writeNextDocument() throws IOException
      Deprecated.
      Doubt this still works as untested.
      Throws:
      IOException
    • writeNextDocument

      @Deprecated public void writeNextDocument(int initialPageNo) throws IOException
      Deprecated.
      Doubt this still works as untested.
      Throws:
      IOException
    • finishPDF

      @Deprecated public void finishPDF() throws IOException
      Deprecated.
      Throws:
      IOException
    • createPDF

      @Deprecated public void createPDF(OutputStream os, boolean finish) throws IOException
      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

      private void createPdfFast(boolean finish, int initialPageNo) throws IOException
      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

      private org.apache.xmpbox.schema.XMPSchema createPdfaSchema(String schema, String namespace, String prefix, List<org.apache.xmpbox.schema.XMPSchema> properties)
    • createPdfaProperty

      private org.apache.xmpbox.schema.XMPSchema createPdfaProperty(String category, String description, String name, 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 String stringfyMetadata(Element element)
    • getFirstChildElement

      private static Element getFirstChildElement(Element element)
    • createXPacket

      private String createXPacket(String metadata)
    • getOutputDevice

      public PdfBoxOutputDevice getOutputDevice()
    • getSharedContext

      public SharedContext getSharedContext()
    • exportText

      @Deprecated public void exportText(Writer writer) throws IOException
      Deprecated.
      unused and untested.
      Parameters:
      writer -
      Throws:
      IOException
    • getRootBox

      public BlockBox getRootBox()
    • getDotsPerPoint

      public float getDotsPerPoint()
    • findPagePositionsByID

      public List<PagePosition<Box>> findPagePositionsByID(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 interface AutoCloseable
      Specified by:
      close in interface 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 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 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.
    • 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

      private int findStartPage(RenderingContext c, Layer layer, List<PageBox> pages)
      Returns the start page for a layer. Transform aware.
    • findEndPage

      private int findEndPage(RenderingContext c, Layer layer, List<PageBox> pages)
      Returns the end page number for a layer. Transform aware.