Class PdfXrefTable

java.lang.Object
com.itextpdf.kernel.pdf.PdfXrefTable

public class PdfXrefTable extends Object
A representation of a cross-referenced table of a PDF document.
  • Field Details

    • INITIAL_CAPACITY

      private static final int INITIAL_CAPACITY
      See Also:
    • MAX_GENERATION

      private static final int MAX_GENERATION
      See Also:
    • MAX_OFFSET_IN_CROSS_REFERENCE_STREAM

      private static final long MAX_OFFSET_IN_CROSS_REFERENCE_STREAM
      The maximum offset in a cross-reference stream. This is a limitation of the PDF specification. SPEC1.7: 7.5.4 Cross reference trailer

      It states that the offset should be a 10-digit byte, so the maximum value is 9999999999. This is the max value that can be represented in 10 bytes.

      See Also:
    • freeXRefEntry

      private static final byte[] freeXRefEntry
    • inUseXRefEntry

      private static final byte[] inUseXRefEntry
    • xref

      private PdfIndirectReference[] xref
    • count

      private int count
    • readingCompleted

      private boolean readingCompleted
    • memoryLimitsAwareHandler

      private MemoryLimitsAwareHandler memoryLimitsAwareHandler
    • freeReferencesLinkedList

      private final TreeMap<Integer,PdfIndirectReference> freeReferencesLinkedList
      Free references linked list is stored in a form of a map, where: key - free reference obj number; value - previous item in the linked list of free references for the object denoted by the key.
  • Constructor Details

    • PdfXrefTable

      public PdfXrefTable()
      Creates a PdfXrefTable which will be used to store xref structure of the pdf document. Capacity and MemoryLimitsAwareHandler instance would be set by default values.
    • PdfXrefTable

      public PdfXrefTable(int capacity)
      Creates a PdfXrefTable which will be used to store xref structure of the pdf document.
      Parameters:
      capacity - initial capacity of xref table.
    • PdfXrefTable

      public PdfXrefTable(MemoryLimitsAwareHandler memoryLimitsAwareHandler)
      Creates a PdfXrefTable which will be used to store xref structure of the pdf document.
      Parameters:
      memoryLimitsAwareHandler - custom MemoryLimitsAwareHandler to set.
    • PdfXrefTable

      public PdfXrefTable(int capacity, MemoryLimitsAwareHandler memoryLimitsAwareHandler)
      Creates a PdfXrefTable which will be used to store xref structure of the pdf document.
      Parameters:
      capacity - initial capacity of xref table.
      memoryLimitsAwareHandler - memoryLimitsAwareHandler custom MemoryLimitsAwareHandler to set.
  • Method Details

    • setMemoryLimitsAwareHandler

      public void setMemoryLimitsAwareHandler(MemoryLimitsAwareHandler memoryLimitsAwareHandler)
      Parameters:
      memoryLimitsAwareHandler - instance to set.
    • add

      Adds indirect reference to list of indirect objects.
      Parameters:
      reference - indirect reference to add.
      Returns:
      reference from param
    • size

      public int size()
      Get size of cross-reference table.
      Returns:
      amount of lines including zero-object
    • getCountOfIndirectObjects

      public int getCountOfIndirectObjects()
      Calculates a number of stored references to indirect objects.
      Returns:
      number of indirect objects
    • get

      public PdfIndirectReference get(int index)
      Get appropriate reference to indirect object.
      Parameters:
      index - is the index of required object
      Returns:
      reference to object with the provided index
    • writeKeyInfo

      protected static void writeKeyInfo(PdfDocument document)
      Convenience method to write the fingerprint preceding the trailer. The fingerprint contains information on iText products used in the generation or manipulation of an outputted PDF file.
      Parameters:
      document - pdfDocument to write the fingerprint to
    • createNextIndirectReference

      protected PdfIndirectReference createNextIndirectReference(PdfDocument document)
      Creates next available indirect reference.
      Parameters:
      document - is the current document
      Returns:
      created indirect reference.
    • freeReference

      protected void freeReference(PdfIndirectReference reference)
      Set the reference to free state.
      Parameters:
      reference - is a reference to be updated.
    • getCapacity

      protected int getCapacity()
      Gets the capacity of xref stream.
      Returns:
      the capacity of xref stream.
    • setCapacity

      protected void setCapacity(int capacity)
      Increase capacity of the array of indirect references.
      Parameters:
      capacity - is a new capacity to set
    • writeXrefTableAndTrailer

      protected void writeXrefTableAndTrailer(PdfDocument document, PdfObject fileId, PdfObject crypto) throws IOException
      Writes cross reference table and trailer to PDF.
      Parameters:
      document - is the current document
      fileId - field id
      crypto - pdf encryption
      Throws:
      IOException - if any I/O error occurs
    • markReadingCompleted

      void markReadingCompleted()
      Change the state of the cross-reference table to mark that reading of the document was completed.
    • unmarkReadingCompleted

      void unmarkReadingCompleted()
      Change the state of the cross-reference table to unmark that reading of the document was completed.
    • isReadingCompleted

      boolean isReadingCompleted()
      Check if reading of the document was completed.
      Returns:
      true if reading was completed and false otherwise
    • initFreeReferencesList

      void initFreeReferencesList(PdfDocument pdfDocument)
      Set up appropriate state for the free references list.
      Parameters:
      pdfDocument - is the current document
    • createNewIndirectReference

      PdfIndirectReference createNewIndirectReference(PdfDocument document)
      Method is used for object streams to avoid reuse existed references.
      Parameters:
      document - is the current document
      Returns:
      created indirect reference to the object stream
    • clear

      void clear()
      Clear the state of the cross-reference table without free references removal.
    • clearAllReferences

      void clearAllReferences()
      Clear the state of the cross-reference table including free references.
    • createSections

      private List<Integer> createSections(PdfDocument document, boolean dropObjectsFromObjectStream)
    • getOffsetSize

      private int getOffsetSize(long startxref)
      Gets size of the offset. Max size is 2^40, i.e. 1 Tb.
    • appendNewRefToFreeList

      private void appendNewRefToFreeList(PdfIndirectReference reference)
    • removeFreeRefFromList

      private PdfIndirectReference removeFreeRefFromList(int freeRefObjNr)
      Removes indirect reference from free references linked list. It does not removes it from xref table and affects only the linked list formed by offset values of free references.
      Parameters:
      freeRefObjNr - object number of the reference to be removed. Removes the free reference with the least object number if this parameter is less than zero: this could be used for finding the next free reference for reusing.
      Returns:
      PdfIndirectReference instance of the removed free reference corresponding to the object number passed as parameter. null - if given object number doesn't correspond to free reference or equals to zero.
    • ensureCount

      private void ensureCount(int count)
    • extendXref

      private void extendXref(int capacity)