Class IncrementablePDDocument

java.lang.Object
org.sejda.sambox.input.IncrementablePDDocument
All Implemented Interfaces:
Closeable, AutoCloseable

public class IncrementablePDDocument extends Object implements Closeable
Model for a document to be used to incrementally update an existing PDF file. Has info regarding PDF objects that need to be replaced in the original document.
Author:
Andrea Vacondio
  • Field Details

    • parser

      public final org.sejda.sambox.input.COSParser parser
  • Method Details

    • incremented

      public PDDocument incremented()
    • trailer

      public FileTrailer trailer()
      Returns:
      the trailer of the incremented document
    • incrementedAsStream

      public InputStream incrementedAsStream() throws IOException
      Returns:
      the incremented document as a stream to be written "as is"
      Throws:
      IOException
    • highestExistingReference

      public COSObjectKey highestExistingReference()
      Returns:
      the highest object reference in the document that is being incrementally updated
    • replace

      public void replace(IndirectCOSObjectIdentifier toReplace, COSObjectable replacement)
      Replaces the object with the given IndirectCOSObjectIdentifier during the incremental update
      Parameters:
      toReplace -
      replacement -
    • modified

      public boolean modified(COSObjectable modified)
      Adds the given object as modified, this object will be written as part of the incremental update.
      Parameters:
      modified -
      Returns:
      true if the COSBase was added, false if not. In case where false is returned, the COSBase doesn't have an id, meaning it's not written as indirect object in the original document but it's written as direct object. In this case we have to call modified(COSBase) on the first indirect parent because incremental updates are meant to replace indirect references.
    • newIndirect

      public void newIndirect(COSObjectable newObject)
      Adds the given object to the set of the new indirect objects. These objects will be written as new indirect objects (with a new object number) as part of the incremental update. If, when writing the incremental update, a new object that was not added using this method is found, it will be written as direct object and no indirect reference will be created.
      Parameters:
      newObject -
    • replacements

      public List<IndirectCOSObjectReference> replacements()
      Returns:
      a list of IndirectCOSObjectReference to be written as replacements for this incremental update
    • newIndirects

      public Set<COSBase> newIndirects()
      Returns:
      a set of objects for which a new indirect reference should be created
    • encryptionDictionary

      public COSDictionary encryptionDictionary()
      Returns:
      the encryption dictionary for the existing document
    • encryptionKey

      public byte[] encryptionKey()
      Returns:
      the encryption key, if the incremented document is encrypted, null otherwise.
    • close

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

      public void writeTo(File file, WriteOption... options) throws IOException
      Writes the document to the given File. The document is closed once written.
      Parameters:
      file -
      options -
      Throws:
      IOException
    • writeTo

      public void writeTo(String filename, WriteOption... options) throws IOException
      Writes the document to the file corresponding the given file name. The document is closed once written.
      Parameters:
      filename -
      options -
      Throws:
      IOException
    • writeTo

      public void writeTo(WritableByteChannel channel, WriteOption... options) throws IOException
      Writes the document to the given WritableByteChannel. The document is closed once written.
      Parameters:
      channel -
      options -
      Throws:
      IOException
    • writeTo

      public void writeTo(OutputStream out, WriteOption... options) throws IOException
      Writes the document to the given OutputStream. The document is closed once written.
      Parameters:
      out -
      options -
      Throws:
      IOException
    • requireMinVersion

      public void requireMinVersion(String version)
      Sets the version for this document if not at the minimum version required
      Parameters:
      version -
    • setVersion

      public void setVersion(String newVersion)