java.lang.Object
org.sejda.sambox.output.PDFWriteContext
Context that contains and keeps track of all the information needed during the process of writing a PDF document. It
creates indirect references for
COSBase instances and provide lookup methods to be able to retrieve these
data and know what's the indirect reference created by the context for a given COSBase. I keeps track of what
object numbers have been written.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Stringprivate static final org.slf4j.Loggerprivate List<WriteOption>private IndirectReferenceProvider -
Constructor Summary
ConstructorsConstructorDescriptionPDFWriteContext(long highestExistingReferenceNumber, GeneralEncryptionAlgorithm encryptor, WriteOption... options) PDFWriteContext(GeneralEncryptionAlgorithm encryptor, WriteOption... options) -
Method Summary
Modifier and TypeMethodDescription(package private) voidadds the reference to the context.(package private) XrefEntryaddWritten(XrefEntry entry) Adds an entry to the list of the written entries(package private) IndirectCOSObjectReferenceCreates a newIndirectCOSObjectReferencefor the given item.private IndirectCOSObjectReferencecreateNewReference(COSBase item, Function<COSBase, IndirectCOSObjectReference> supplier) (package private) IndirectCOSObjectReferenceCreates an emptyNonStorableInObjectStreams(package private) IndirectCOSObjectReferenceCreates a newNonStorableInObjectStreamsfor the given item.(package private) IndirectCOSObjectReference(package private) IndirectCOSObjectReferenceCreates a newIndirectCOSObjectReferencefor the given item if it has not been created before, it returns the already existing reference otherwise.(package private) XrefEntrygetWritten(Long objectNumber) (package private) boolean(package private) boolean(package private) booleanhasWritten(XrefEntry entry) (package private) long(package private) XrefEntry(package private) voidwriting(COSObjectKey key) Informs the context of the object is about the written(package private) intwritten()
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
contextId
-
referencesProvider
-
lookupNewRef
-
opts
-
written
-
encryptor
-
-
Constructor Details
-
PDFWriteContext
PDFWriteContext(GeneralEncryptionAlgorithm encryptor, WriteOption... options) -
PDFWriteContext
PDFWriteContext(long highestExistingReferenceNumber, GeneralEncryptionAlgorithm encryptor, WriteOption... options)
-
-
Method Details
-
createIndirectReferenceFor
Creates a newIndirectCOSObjectReferencefor the given item. We store the association between the item id and the reference so that if we meet the same id later, we can retrieve the reference that was previously written.- Parameters:
item-- Returns:
- the created reference
-
createNonStorableInObjectStreamIndirectReferenceFor
Creates a newNonStorableInObjectStreamsfor the given item. We store the association between the item id and the reference so that if we meet the same id later, we can retrieve the reference that was previously written.- Parameters:
item-- Returns:
- the created reference
-
createNonStorableInObjectStreamIndirectReference
IndirectCOSObjectReference createNonStorableInObjectStreamIndirectReference()Creates an emptyNonStorableInObjectStreams- Returns:
- the created reference
-
createNewReference
private IndirectCOSObjectReference createNewReference(COSBase item, Function<COSBase, IndirectCOSObjectReference> supplier) -
getOrCreateIndirectReferenceFor
Creates a newIndirectCOSObjectReferencefor the given item if it has not been created before, it returns the already existing reference otherwise.- Parameters:
item-- Returns:
- the reference
-
getIndirectReferenceFor
- Parameters:
item-- Returns:
- the
IndirectCOSObjectReferencefor the given item or null if anIndirectCOSObjectReferencehas not been created for the item or the item has no id.
-
addExistingReference
adds the reference to the context. When later queried, the context will return the existing indirect reference an no new reference will be created. This is used during incremental updates when we don't want to create new references for existing objects- Parameters:
existing-
-
hasIndirectReferenceFor
- Parameters:
item-- Returns:
- true if the given item has been added to the context and an indirect reference created for it.
-
hasWriteOption
- Parameters:
opt-- Returns:
- true if the context has the given write option
-
written
int written()- Returns:
- number of written objects so far.
-
hasWritten
- Parameters:
entry-- Returns:
- true if the given entry has been already written
-
addWritten
Adds an entry to the list of the written entries- Parameters:
entry-- Returns:
- the previous value if an entry with the same object number has been already written, null otherwise.
-
highestWritten
XrefEntry highestWritten()- Returns:
- the written entry with the highest object number
-
highestObjectNumber
long highestObjectNumber()- Returns:
- the highest object number that this context knows
-
getWritten
- Parameters:
objectNumber-- Returns:
- the written entry with the given object number if any, null otherwise.
-
getWrittenContiguousGroups
- Returns:
- a list of contiguous groups of written object numbers
-
writing
Informs the context of the object is about the written- Parameters:
key-
-