Class PdfDocument

java.lang.Object
org.openpdf.text.Document
org.openpdf.text.pdf.PdfDocument
All Implemented Interfaces:
AutoCloseable, EventListener, DocListener, ElementListener

public class PdfDocument extends Document
PdfDocument is the class that is used by PdfWriter to translate a Document into a PDF with different pages.

This pruned version only manages pages (that are filled by the content of the writer), the information dictionary, the catalog and the annotations of the pages. The layout of text, tables and images is not supported.

See Also:
  • Field Details

    • writer

      protected PdfWriter writer
      The writer associated to this document.
    • text

      protected PdfContentByte text
      The PdfContentByte object that contains the text, the graphics and the images of the page.
    • graphics

      protected PdfContentByte graphics
    • info

      protected PdfDocument.PdfInfo info
      The info dictionary.
    • thisBoxSize

      protected HashMap<String,PdfRectangle> thisBoxSize
      The boxes of the pages (crop box...).
    • boxSize

      protected HashMap<String,PdfRectangle> boxSize
    • pageResources

      protected org.openpdf.text.pdf.PageResources pageResources
      The resources of the current page.
  • Constructor Details

    • PdfDocument

      public PdfDocument()
      Constructs a new PDF document.
  • Method Details

    • addWriter

      public void addWriter(PdfWriter writer) throws DocumentException
      Adds a PdfWriter to the PdfDocument.
      Parameters:
      writer - the PdfWriter
      Throws:
      DocumentException - on error
    • open

      public void open()
      Opens the document.
      Specified by:
      open in interface DocListener
      Overrides:
      open in class Document
    • close

      public void close()
      Closes the document.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface DocListener
      Overrides:
      close in class Document
    • add

      public boolean add(Element element) throws DocumentException
      Signals that an Element was added to the Document. Only the meta information is supported by this pruned version.
      Specified by:
      add in interface ElementListener
      Overrides:
      add in class Document
      Parameters:
      element - the element to add
      Returns:
      true if the element was added, false if not.
      Throws:
      DocumentException - when a document isn't open yet, or has been closed
    • newPage

      public boolean newPage()
      Makes a new page and sends it to the PdfWriter.
      Specified by:
      newPage in interface DocListener
      Overrides:
      newPage in class Document
      Returns:
      a boolean
    • setPageSize

      public boolean setPageSize(Rectangle pageSize)
      Sets the pagesize.
      Specified by:
      setPageSize in interface DocListener
      Overrides:
      setPageSize in class Document
      Parameters:
      pageSize - the new pagesize
      Returns:
      true if the page size was set
    • setMargins

      public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
      Sets the margins.
      Specified by:
      setMargins in interface DocListener
      Overrides:
      setMargins in class Document
      Parameters:
      marginLeft - the margin on the left
      marginRight - the margin on the right
      marginTop - the margin on the top
      marginBottom - the margin on the bottom
      Returns:
      a boolean
    • initPage

      protected void initPage() throws DocumentException
      Initializes a page.
      Throws:
      DocumentException - on error
    • setNewPageSizeAndMargins

      protected void setNewPageSizeAndMargins()
    • getInfo

      protected PdfDocument.PdfInfo getInfo()
      Gets the info dictionary.
      Returns:
      the info dictionary