Class PDDocumentHandler

java.lang.Object
org.sejda.impl.sambox.component.PDDocumentHandler
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
PdfAlternateMixer

public class PDDocumentHandler extends Object implements Closeable
Wrapper over a PDDocument.
Author:
Andrea Vacondio
  • Field Details

  • Constructor Details

    • PDDocumentHandler

      public PDDocumentHandler(org.sejda.sambox.pdmodel.PDDocument document)
      Creates a new handler using the given document as underlying PDDocument.
      Parameters:
      document -
    • PDDocumentHandler

      public PDDocumentHandler()
      Creates a new handler with an empty underlying PDDocument.
  • Method Details

    • setCreatorOnPDDocument

      public void setCreatorOnPDDocument()
      set the creator on the underlying PDDocument
    • setDocumentInformation

      public void setDocumentInformation(org.sejda.sambox.pdmodel.PDDocumentInformation info)
      Set the document information on the underlying PDDocument
      Parameters:
      info -
    • setDocumentTitle

      public void setDocumentTitle(String title)
    • getPermissions

      public PDDocumentAccessPermission getPermissions()
      Returns:
      access permissions granted to this document.
    • setPageLayoutOnDocument

      public void setPageLayoutOnDocument(PdfPageLayout layout)
      Sets the given page layout on the underlying PDDocument.
      Parameters:
      layout -
    • setPageModeOnDocument

      public void setPageModeOnDocument(PdfPageMode mode)
      Sets the given page mode on the underlying PDDocument.
      Parameters:
      mode -
    • setPageLabelsOnDocument

      public void setPageLabelsOnDocument(Map<Integer,PdfPageLabel> labels)
      Sets the page labels on the underlying PDDocument.
      Parameters:
      labels -
    • setVersionOnPDDocument

      public void setVersionOnPDDocument(PdfVersion version)
      Sets the version on the underlying PDDocument.
      Parameters:
      version -
    • addWriteOption

      public void addWriteOption(org.sejda.sambox.output.WriteOption... opts)
      Adds the given WriteOptions to be used when the document is saved
      Parameters:
      opts -
    • removeWriteOption

      public void removeWriteOption(org.sejda.sambox.output.WriteOption... opts)
      Removes the given WriteOptions to be used when the document is saved
      Parameters:
      opts -
    • setCompress

      public void setCompress(boolean compress)
      sets or remove compression options to be used when the resulting document is written
    • getViewerPreferences

      public org.sejda.sambox.pdmodel.interactive.viewerpreferences.PDViewerPreferences getViewerPreferences()
      Returns:
      the view preferences for the underlying PDDocument.
    • setViewerPreferences

      public void setViewerPreferences(org.sejda.sambox.pdmodel.interactive.viewerpreferences.PDViewerPreferences preferences)
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • savePDDocument

      public void savePDDocument(File file) throws TaskException
      Throws:
      TaskException
    • savePDDocument

      public void savePDDocument(File file, EncryptionAtRestPolicy encryptionAtRestSecurity) throws TaskException
      Saves the underlying PDDocument to the given file.
      Parameters:
      file -
      Throws:
      TaskException
    • savePDDocument

      public void savePDDocument(File file, org.sejda.sambox.encryption.StandardSecurity security, EncryptionAtRestPolicy encryptionAtRestSecurity) throws TaskException
      Saves the underlying PDDocument to the given file and using the given standard security.
      Parameters:
      file -
      security -
      Throws:
      TaskException
    • getNumberOfPages

      public int getNumberOfPages()
    • getUnderlyingPDDocument

      public org.sejda.sambox.pdmodel.PDDocument getUnderlyingPDDocument()
    • catalog

      public org.sejda.sambox.pdmodel.PDDocumentCatalog catalog()
    • importPage

      public org.sejda.sambox.pdmodel.PDPage importPage(org.sejda.sambox.pdmodel.PDPage page)
      Creates a copy of the given page and adds it to the underlying PDDocument
      Parameters:
      page -
      Returns:
      The newly created page
    • addPage

      public org.sejda.sambox.pdmodel.PDPage addPage(org.sejda.sambox.pdmodel.PDPage page)
      Adds the given page to the underlying PDDocument
      Parameters:
      page -
      Returns:
      the page
    • removePage

      public void removePage(int pageNumber)
      Removes the given page to the underlying PDDocument
      Parameters:
      pageNumber -
    • movePageToDocumentEnd

      public void movePageToDocumentEnd(int oldPageNumber)
      Moves designated page to the end of the document.
      Parameters:
      oldPageNumber - 1-based page number
    • getPage

      public org.sejda.sambox.pdmodel.PDPage getPage(int pageNumber)
    • getPages

      public org.sejda.sambox.pdmodel.PDPageTree getPages()
    • initialiseBasedOn

      public void initialiseBasedOn(org.sejda.sambox.pdmodel.PDDocument other)
    • renderImage

      public BufferedImage renderImage(int pageNumber, int dpi, ImageColorType type) throws TaskException
      Throws:
      TaskException
    • setDocumentOutline

      public void setDocumentOutline(org.sejda.sambox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline outline)
    • setDocumentAcroForm

      public void setDocumentAcroForm(org.sejda.sambox.pdmodel.interactive.form.PDAcroForm acroForm)
    • addBlankPageIfOdd

      public org.sejda.sambox.pdmodel.PDPage addBlankPageIfOdd(org.sejda.sambox.pdmodel.common.PDRectangle mediaBox)
      Adds a blank page if the current total pages number is odd
      Parameters:
      mediaBox - media box size for the blank page
      Returns:
      the added page or null if no page has been added
    • addBlankPage

      public org.sejda.sambox.pdmodel.PDPage addBlankPage(org.sejda.sambox.pdmodel.common.PDRectangle mediaBox)
    • addBlankPageAfter

      public org.sejda.sambox.pdmodel.PDPage addBlankPageAfter(int pageNumber)
    • addBlankPageBefore

      public org.sejda.sambox.pdmodel.PDPage addBlankPageBefore(int pageNumber)
    • isUpdateProducerModifiedDate

      public boolean isUpdateProducerModifiedDate()
    • setUpdateProducerModifiedDate

      public void setUpdateProducerModifiedDate(boolean updateProducerModifiedDate)