public class MemoryLimitsAwareHandler extends Object
The handler is primarily used during decoding (decompression) of PDF streams, but also guards against other potentially unbounded structures during reading, e.g. cross-reference (xref) table growth and per-page XObject usage.
A configured handler can be set on ReaderProperties and will be used by PdfReader when opening
a document.
| Constructor and Description |
|---|
MemoryLimitsAwareHandler()
Creates a
MemoryLimitsAwareHandler to handle decompression of PDF streams and other memory-related limits
during reading. |
MemoryLimitsAwareHandler(long documentSize)
Creates a
MemoryLimitsAwareHandler with calculated memory limits
for decompression and xref structures based on the provided document size. |
| Modifier and Type | Method and Description |
|---|---|
protected static int |
calculateMaxElementsInXref(long documentSizeInBytes)
Calculate max number of elements allowed in xref table based on the size of the document, achieving max limit at 100MB.
|
void |
checkIfPageSizeExceedsTheLimit(long totalXObjectsSize) |
void |
checkIfXrefStructureExceedsTheLimit(int requestedCapacity)
Performs a check of possible extension of xref structure.
|
MemoryLimitsAwareHandler |
createNewInstance()
Creates a new instance of
MemoryLimitsAwareHandler by copying settings from this instance
of MemoryLimitsAwareHandler. |
int |
getMaxNumberOfElementsInXrefStructure()
Gets maximum number of elements in xref structure.
|
long |
getMaxSizeOfDecompressedPdfStreamsSum()
Gets the maximum allowed size which can be occupied by all decompressed pdf streams.
|
int |
getMaxSizeOfSingleDecompressedPdfStream()
Returns the maximum allowed size (in bytes) of a single decompressed PDF stream.
|
long |
getMaxXObjectsSizePerPage()
Gets maximum page size.
|
boolean |
isMemoryLimitsAwarenessRequiredOnDecompression(PdfArray filters)
Performs a check if the
PdfStream with provided setup of the filters requires
memory limits awareness during decompression. |
void |
setMaxNumberOfElementsInXrefStructure(int maxNumberOfElementsInXrefStructure)
Sets maximum number of elements in xref structure.
|
MemoryLimitsAwareHandler |
setMaxSizeOfDecompressedPdfStreamsSum(long maxSizeOfDecompressedPdfStreamsSum)
Sets the maximum allowed size which can be occupied by all decompressed pdf streams.
|
MemoryLimitsAwareHandler |
setMaxSizeOfSingleDecompressedPdfStream(int maxSizeOfSingleDecompressedPdfStream)
Sets the maximum allowed size which can be occupied by a single decompressed pdf stream.
|
void |
setMaxXObjectsSizePerPage(long maxPageSize)
Sets maximum page size.
|
public MemoryLimitsAwareHandler()
MemoryLimitsAwareHandler to handle decompression of PDF streams and other memory-related limits
during reading.public MemoryLimitsAwareHandler(long documentSize)
MemoryLimitsAwareHandler with calculated memory limits
for decompression and xref structures based on the provided document size.documentSize - the size of the document (in bytes).public MemoryLimitsAwareHandler createNewInstance()
MemoryLimitsAwareHandler by copying settings from this instance
of MemoryLimitsAwareHandler.MemoryLimitsAwareHandler.public int getMaxSizeOfSingleDecompressedPdfStream()
public MemoryLimitsAwareHandler setMaxSizeOfSingleDecompressedPdfStream(int maxSizeOfSingleDecompressedPdfStream)
iText will throw an exception if during decompression a pdf stream which was identified as requiring memory limits awareness occupies more memory than allowed.
maxSizeOfSingleDecompressedPdfStream - the maximum allowed size which can be occupied by a single
decompressed pdf stream.MemoryLimitsAwareHandler instance.isMemoryLimitsAwarenessRequiredOnDecompression(PdfArray)public long getMaxSizeOfDecompressedPdfStreamsSum()
public MemoryLimitsAwareHandler setMaxSizeOfDecompressedPdfStreamsSum(long maxSizeOfDecompressedPdfStreamsSum)
iText will throw an exception if during decompression pdf streams which were identified as requiring memory limits awareness occupy more memory than allowed.
maxSizeOfDecompressedPdfStreamsSum - he maximum allowed size which can be occupied by all decompressed pdf
streams.MemoryLimitsAwareHandler instance.isMemoryLimitsAwarenessRequiredOnDecompression(PdfArray)public boolean isMemoryLimitsAwarenessRequiredOnDecompression(PdfArray filters)
PdfStream with provided setup of the filters requires
memory limits awareness during decompression.filters - is an PdfArray of names of filterspublic int getMaxNumberOfElementsInXrefStructure()
public long getMaxXObjectsSizePerPage()
public void setMaxXObjectsSizePerPage(long maxPageSize)
maxPageSize - maximum page size.public void setMaxNumberOfElementsInXrefStructure(int maxNumberOfElementsInXrefStructure)
maxNumberOfElementsInXrefStructure - maximum number of elements in xref structure.public void checkIfXrefStructureExceedsTheLimit(int requestedCapacity)
requestedCapacity - capacity to which we need to expand xref array.public void checkIfPageSizeExceedsTheLimit(long totalXObjectsSize)
protected static int calculateMaxElementsInXref(long documentSizeInBytes)
documentSizeInBytes - document size in bytes.Copyright © 1998–2026 Apryse Group NV. All rights reserved.