Package com.itextpdf.kernel.pdf
Class PdfXrefTable
java.lang.Object
com.itextpdf.kernel.pdf.PdfXrefTable
A representation of a cross-referenced table of a PDF document.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private final TreeMap
<Integer, PdfIndirectReference> 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.private static final byte[]
private static final int
private static final byte[]
private static final int
private static final long
The maximum offset in a cross-reference stream.private MemoryLimitsAwareHandler
private boolean
private PdfIndirectReference[]
-
Constructor Summary
ConstructorsConstructorDescriptionCreates aPdfXrefTable
which will be used to store xref structure of the pdf document.PdfXrefTable
(int capacity) Creates aPdfXrefTable
which will be used to store xref structure of the pdf document.PdfXrefTable
(int capacity, MemoryLimitsAwareHandler memoryLimitsAwareHandler) Creates aPdfXrefTable
which will be used to store xref structure of the pdf document.PdfXrefTable
(MemoryLimitsAwareHandler memoryLimitsAwareHandler) Creates aPdfXrefTable
which will be used to store xref structure of the pdf document. -
Method Summary
Modifier and TypeMethodDescriptionadd
(PdfIndirectReference reference) Adds indirect reference to list of indirect objects.private void
appendNewRefToFreeList
(PdfIndirectReference reference) (package private) void
clear()
Clear the state of the cross-reference table without free references removal.(package private) void
Clear the state of the cross-reference table including free references.(package private) PdfIndirectReference
createNewIndirectReference
(PdfDocument document) Method is used for object streams to avoid reuse existed references.protected PdfIndirectReference
createNextIndirectReference
(PdfDocument document) Creates next available indirect reference.createSections
(PdfDocument document, boolean dropObjectsFromObjectStream) private void
ensureCount
(int count) private void
extendXref
(int capacity) protected void
freeReference
(PdfIndirectReference reference) Set the reference to free state.get
(int index) Get appropriate reference to indirect object.protected int
Gets the capacity of xref stream.int
Calculates a number of stored references to indirect objects.private int
getOffsetSize
(long startxref) Gets size of the offset.(package private) void
initFreeReferencesList
(PdfDocument pdfDocument) Set up appropriate state for the free references list.(package private) boolean
Check if reading of the document was completed.(package private) void
Change the state of the cross-reference table to mark that reading of the document was completed.private PdfIndirectReference
removeFreeRefFromList
(int freeRefObjNr) Removes indirect reference from free references linked list.protected void
setCapacity
(int capacity) Increase capacity of the array of indirect references.void
setMemoryLimitsAwareHandler
(MemoryLimitsAwareHandler memoryLimitsAwareHandler) Sets customMemoryLimitsAwareHandler
.int
size()
Get size of cross-reference table.(package private) void
Change the state of the cross-reference table to unmark that reading of the document was completed.protected void
writeXrefTableAndTrailer
(PdfDocument document, PdfObject fileId, PdfObject crypto) Writes cross reference table and trailer to PDF.
-
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_STREAMThe maximum offset in a cross-reference stream. This is a limitation of the PDF specification. SPEC1.7: 7.5.4 Cross reference trailerIt 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
-
count
private int count -
readingCompleted
private boolean readingCompleted -
memoryLimitsAwareHandler
-
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 aPdfXrefTable
which will be used to store xref structure of the pdf document. Capacity andMemoryLimitsAwareHandler
instance would be set by default values. -
PdfXrefTable
public PdfXrefTable(int capacity) Creates aPdfXrefTable
which will be used to store xref structure of the pdf document.- Parameters:
capacity
- initial capacity of xref table.
-
PdfXrefTable
Creates aPdfXrefTable
which will be used to store xref structure of the pdf document.- Parameters:
memoryLimitsAwareHandler
- customMemoryLimitsAwareHandler
to set.
-
PdfXrefTable
Creates aPdfXrefTable
which will be used to store xref structure of the pdf document.- Parameters:
capacity
- initial capacity of xref table.memoryLimitsAwareHandler
- memoryLimitsAwareHandler customMemoryLimitsAwareHandler
to set.
-
-
Method Details
-
setMemoryLimitsAwareHandler
Sets customMemoryLimitsAwareHandler
.- 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
Get appropriate reference to indirect object.- Parameters:
index
- is the index of required object- Returns:
- reference to object with the provided index
-
createNextIndirectReference
Creates next available indirect reference.- Parameters:
document
- is the currentdocument
- Returns:
- created indirect reference.
-
freeReference
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 currentdocument
fileId
- field idcrypto
- 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
Set up appropriate state for the free references list.- Parameters:
pdfDocument
- is the currentdocument
-
createNewIndirectReference
Method is used for object streams to avoid reuse existed references.- Parameters:
document
- is the currentdocument
- 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
-
getOffsetSize
private int getOffsetSize(long startxref) Gets size of the offset. Max size is 2^40, i.e. 1 Tb. -
appendNewRefToFreeList
-
removeFreeRefFromList
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)
-