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 intprivate 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 intprivate static final byte[]private static final intprivate static final longThe maximum offset in a cross-reference stream.private MemoryLimitsAwareHandlerprivate booleanprivate PdfIndirectReference[] -
Constructor Summary
ConstructorsConstructorDescriptionCreates aPdfXrefTablewhich will be used to store xref structure of the pdf document.PdfXrefTable(int capacity) Creates aPdfXrefTablewhich will be used to store xref structure of the pdf document.PdfXrefTable(int capacity, MemoryLimitsAwareHandler memoryLimitsAwareHandler) Creates aPdfXrefTablewhich will be used to store xref structure of the pdf document.PdfXrefTable(MemoryLimitsAwareHandler memoryLimitsAwareHandler) Creates aPdfXrefTablewhich 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 voidappendNewRefToFreeList(PdfIndirectReference reference) (package private) voidclear()Clear the state of the cross-reference table without free references removal.(package private) voidClear the state of the cross-reference table including free references.(package private) PdfIndirectReferencecreateNewIndirectReference(PdfDocument document) Method is used for object streams to avoid reuse existed references.protected PdfIndirectReferencecreateNextIndirectReference(PdfDocument document) Creates next available indirect reference.createSections(PdfDocument document, boolean dropObjectsFromObjectStream) private voidensureCount(int count) private voidextendXref(int capacity) protected voidfreeReference(PdfIndirectReference reference) Set the reference to free state.get(int index) Get appropriate reference to indirect object.protected intGets the capacity of xref stream.intCalculates a number of stored references to indirect objects.private intgetOffsetSize(long startxref) Gets size of the offset.(package private) voidinitFreeReferencesList(PdfDocument pdfDocument) Set up appropriate state for the free references list.(package private) booleanCheck if reading of the document was completed.(package private) voidChange the state of the cross-reference table to mark that reading of the document was completed.private PdfIndirectReferenceremoveFreeRefFromList(int freeRefObjNr) Removes indirect reference from free references linked list.protected voidsetCapacity(int capacity) Increase capacity of the array of indirect references.voidsetMemoryLimitsAwareHandler(MemoryLimitsAwareHandler memoryLimitsAwareHandler) Sets customMemoryLimitsAwareHandler.intsize()Get size of cross-reference table.(package private) voidChange the state of the cross-reference table to unmark that reading of the document was completed.protected voidwriteXrefTableAndTrailer(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 aPdfXrefTablewhich will be used to store xref structure of the pdf document. Capacity andMemoryLimitsAwareHandlerinstance would be set by default values. -
PdfXrefTable
public PdfXrefTable(int capacity) Creates aPdfXrefTablewhich will be used to store xref structure of the pdf document.- Parameters:
capacity- initial capacity of xref table.
-
PdfXrefTable
Creates aPdfXrefTablewhich will be used to store xref structure of the pdf document.- Parameters:
memoryLimitsAwareHandler- customMemoryLimitsAwareHandlerto set.
-
PdfXrefTable
Creates aPdfXrefTablewhich will be used to store xref structure of the pdf document.- Parameters:
capacity- initial capacity of xref table.memoryLimitsAwareHandler- memoryLimitsAwareHandler customMemoryLimitsAwareHandlerto 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 currentdocumentfileId- 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:
PdfIndirectReferenceinstance 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)
-