Package com.itextpdf.kernel.pdf
Class PdfXrefTable
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfXrefTable
-
public class PdfXrefTable extends java.lang.ObjectA representation of a cross-referenced table of a PDF document.
-
-
Field Summary
Fields Modifier and Type Field Description private intcountprivate java.util.TreeMap<java.lang.Integer,PdfIndirectReference>freeReferencesLinkedListFree 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 byte[]freeXRefEntryprivate static intINITIAL_CAPACITYprivate static byte[]inUseXRefEntryprivate static intMAX_GENERATIONprivate static longMAX_OFFSET_IN_CROSS_REFERENCE_STREAMThe maximum offset in a cross-reference stream.private MemoryLimitsAwareHandlermemoryLimitsAwareHandlerprivate booleanreadingCompletedprivate PdfIndirectReference[]xref
-
Constructor Summary
Constructors Constructor Description PdfXrefTable()Creates 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PdfIndirectReferenceadd(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) voidclearAllReferences()Clear 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.private java.util.List<java.lang.Integer>createSections(PdfDocument document, boolean dropObjectsFromObjectStream)private voidensureCount(int count)private voidextendXref(int capacity)protected voidfreeReference(PdfIndirectReference reference)Set the reference to free state.PdfIndirectReferenceget(int index)Get appropriate reference to indirect object.protected intgetCapacity()Gets the capacity of xref stream.intgetCountOfIndirectObjects()Calculates 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) booleanisReadingCompleted()Check if reading of the document was completed.(package private) voidmarkReadingCompleted()Change 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) voidunmarkReadingCompleted()Change 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 Detail
-
INITIAL_CAPACITY
private static final int INITIAL_CAPACITY
- See Also:
- Constant Field Values
-
MAX_GENERATION
private static final int MAX_GENERATION
- See Also:
- Constant Field Values
-
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 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:
- Constant Field Values
-
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 java.util.TreeMap<java.lang.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 Detail
-
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
public PdfXrefTable(MemoryLimitsAwareHandler memoryLimitsAwareHandler)
Creates aPdfXrefTablewhich will be used to store xref structure of the pdf document.- Parameters:
memoryLimitsAwareHandler- customMemoryLimitsAwareHandlerto set.
-
PdfXrefTable
public PdfXrefTable(int capacity, MemoryLimitsAwareHandler memoryLimitsAwareHandler)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 Detail
-
setMemoryLimitsAwareHandler
public void setMemoryLimitsAwareHandler(MemoryLimitsAwareHandler memoryLimitsAwareHandler)
Sets customMemoryLimitsAwareHandler.- Parameters:
memoryLimitsAwareHandler- instance to set.
-
add
public PdfIndirectReference add(PdfIndirectReference reference)
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
-
createNextIndirectReference
protected PdfIndirectReference createNextIndirectReference(PdfDocument document)
Creates next available indirect reference.- Parameters:
document- is the currentdocument- 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 java.io.IOException
Writes cross reference table and trailer to PDF.- Parameters:
document- is the currentdocumentfileId- field idcrypto- pdf encryption- Throws:
java.io.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 currentdocument
-
createNewIndirectReference
PdfIndirectReference createNewIndirectReference(PdfDocument document)
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
private java.util.List<java.lang.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:
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)
-
-