Class PDFWriteContext

java.lang.Object
org.sejda.sambox.output.PDFWriteContext

class PDFWriteContext extends Object
Context that contains and keeps track of all the information needed during the process of writing a PDF document. It creates indirect references for COSBase instances and provide lookup methods to be able to retrieve these data and know what's the indirect reference created by the context for a given COSBase. I keeps track of what object numbers have been written.
  • Field Details

  • Constructor Details

  • Method Details

    • createIndirectReferenceFor

      IndirectCOSObjectReference createIndirectReferenceFor(COSBase item)
      Creates a new IndirectCOSObjectReference for the given item. We store the association between the item id and the reference so that if we meet the same id later, we can retrieve the reference that was previously written.
      Parameters:
      item -
      Returns:
      the created reference
    • createNonStorableInObjectStreamIndirectReferenceFor

      IndirectCOSObjectReference createNonStorableInObjectStreamIndirectReferenceFor(COSBase item)
      Creates a new NonStorableInObjectStreams for the given item. We store the association between the item id and the reference so that if we meet the same id later, we can retrieve the reference that was previously written.
      Parameters:
      item -
      Returns:
      the created reference
    • createNonStorableInObjectStreamIndirectReference

      IndirectCOSObjectReference createNonStorableInObjectStreamIndirectReference()
      Returns:
      the created reference
    • createNewReference

      private IndirectCOSObjectReference createNewReference(COSBase item, Function<COSBase,IndirectCOSObjectReference> supplier)
    • getOrCreateIndirectReferenceFor

      IndirectCOSObjectReference getOrCreateIndirectReferenceFor(COSBase item)
      Creates a new IndirectCOSObjectReference for the given item if it has not been created before, it returns the already existing reference otherwise.
      Parameters:
      item -
      Returns:
      the reference
    • getIndirectReferenceFor

      IndirectCOSObjectReference getIndirectReferenceFor(COSBase item)
      Parameters:
      item -
      Returns:
      the IndirectCOSObjectReference for the given item or null if an IndirectCOSObjectReference has not been created for the item or the item has no id.
    • addExistingReference

      void addExistingReference(ExistingIndirectCOSObject existing)
      adds the reference to the context. When later queried, the context will return the existing indirect reference an no new reference will be created. This is used during incremental updates when we don't want to create new references for existing objects
      Parameters:
      existing -
    • hasIndirectReferenceFor

      boolean hasIndirectReferenceFor(COSBase item)
      Parameters:
      item -
      Returns:
      true if the given item has been added to the context and an indirect reference created for it.
    • hasWriteOption

      boolean hasWriteOption(WriteOption opt)
      Parameters:
      opt -
      Returns:
      true if the context has the given write option
    • written

      int written()
      Returns:
      number of written objects so far.
    • hasWritten

      boolean hasWritten(XrefEntry entry)
      Parameters:
      entry -
      Returns:
      true if the given entry has been already written
    • addWritten

      XrefEntry addWritten(XrefEntry entry)
      Adds an entry to the list of the written entries
      Parameters:
      entry -
      Returns:
      the previous value if an entry with the same object number has been already written, null otherwise.
    • highestWritten

      XrefEntry highestWritten()
      Returns:
      the written entry with the highest object number
    • highestObjectNumber

      long highestObjectNumber()
      Returns:
      the highest object number that this context knows
    • getWritten

      XrefEntry getWritten(Long objectNumber)
      Parameters:
      objectNumber -
      Returns:
      the written entry with the given object number if any, null otherwise.
    • getWrittenContiguousGroups

      List<List<Long>> getWrittenContiguousGroups()
      Returns:
      a list of contiguous groups of written object numbers
    • writing

      void writing(COSObjectKey key)
      Informs the context of the object is about the written
      Parameters:
      key -