public class COSDocument extends COSBase implements java.io.Closeable
Modifier and Type | Field and Description |
---|---|
private boolean |
closed |
private long |
highestXRefObjectNumber
Used for incremental saving, to avoid XRef object numbers from being reused.
|
private boolean |
isDecrypted
Signal that document is already decrypted.
|
private boolean |
isXRefStream |
private static org.apache.commons.logging.Log |
LOG
Log instance.
|
private java.util.Map<COSObjectKey,COSObject> |
objectPool
Maps ObjectKeys to a COSObject.
|
private ScratchFile |
scratchFile |
private long |
startXref |
private java.util.List<COSStream> |
streams
List containing all streams which are created when creating a new pdf.
|
private COSDictionary |
trailer
Document trailer dictionary.
|
private float |
version |
private boolean |
warnMissingClose |
private java.util.Map<COSObjectKey,java.lang.Long> |
xrefTable
Maps object and generation id to object byte offsets.
|
Constructor and Description |
---|
COSDocument()
Constructor.
|
COSDocument(ScratchFile scratchFile)
Constructor that will use the provide memory handler for storage of the
PDF streams.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
accept(ICOSVisitor visitor)
visitor pattern double dispatch method.
|
void |
addXRefTable(java.util.Map<COSObjectKey,java.lang.Long> xrefTableValues)
Populate XRef HashMap with given values.
|
void |
close()
This will close all storage and delete the tmp files.
|
COSStream |
createCOSStream()
Creates a new COSStream using the current configuration for scratch files.
|
COSStream |
createCOSStream(COSDictionary dictionary)
Creates a new COSStream using the current configuration for scratch files.
|
void |
dereferenceObjectStreams()
This method will search the list of objects for types of ObjStm.
|
protected void |
finalize()
Warn the user in the finalizer if he didn't close the PDF document.
|
COSObject |
getCatalog()
Deprecated.
use
PDDocument.getDocumentCatalog() instead. |
COSArray |
getDocumentID()
This will get the document ID.
|
COSDictionary |
getEncryptionDictionary()
This will get the encryption dictionary if the document is encrypted or null if the document
is not encrypted.
|
long |
getHighestXRefObjectNumber()
Internal PDFBox use only.
|
COSObjectKey |
getKey(COSBase object)
Returns the COSObjectKey for a given COS object, or null if there is none.
|
COSObject |
getObjectByType(COSName type)
This will get the first dictionary object by type.
|
COSObject |
getObjectFromPool(COSObjectKey key)
This will get an object from the pool.
|
java.util.List<COSObject> |
getObjects()
This will get a list of all available objects.
|
java.util.List<COSObject> |
getObjectsByType(COSName type)
This will get a dictionary object by type.
|
java.util.List<COSObject> |
getObjectsByType(java.lang.String type)
This will get all dictionary objects by type.
|
long |
getStartXref()
Return the startXref Position of the parsed document.
|
COSDictionary |
getTrailer()
This will get the document trailer.
|
float |
getVersion()
This will get the version extracted from the header of this PDF document.
|
java.util.Map<COSObjectKey,java.lang.Long> |
getXrefTable()
Returns the xrefTable which is a mapping of ObjectKeys
to byte offsets in the file.
|
boolean |
isClosed()
Returns true if this document has been closed.
|
boolean |
isDecrypted()
Indicates if a encrypted pdf is already decrypted after parsing.
|
boolean |
isEncrypted()
This will tell if this is an encrypted document.
|
boolean |
isXRefStream()
Determines if the trailer is a XRef stream or not.
|
void |
print()
This will print contents to stdout.
|
COSObject |
removeObject(COSObjectKey key)
Removes an object from the object pool.
|
void |
setDecrypted()
Signals that the document is decrypted completely.
|
void |
setDocumentID(COSArray id)
This will set the document ID.
|
void |
setEncryptionDictionary(COSDictionary encDictionary)
This will set the encryption dictionary, this should only be called when
encrypting the document.
|
void |
setHighestXRefObjectNumber(long highestXRefObjectNumber)
Internal PDFBox use only.
|
void |
setIsXRefStream(boolean isXRefStreamValue)
Sets isXRefStream to the given value.
|
void |
setStartXref(long startXrefValue)
This method set the startxref value of the document.
|
void |
setTrailer(COSDictionary newTrailer)
// MIT added, maybe this should not be supported as trailer is a persistence construct.
|
void |
setVersion(float versionValue)
This will set the header version of this PDF document.
|
void |
setWarnMissingClose(boolean warn)
Controls whether this instance shall issue a warning if the PDF document wasn't closed
properly through a call to the
close() method. |
getCOSObject, isDirect, setDirect
private static final org.apache.commons.logging.Log LOG
private float version
private final java.util.Map<COSObjectKey,COSObject> objectPool
private final java.util.Map<COSObjectKey,java.lang.Long> xrefTable
private final java.util.List<COSStream> streams
private COSDictionary trailer
private boolean warnMissingClose
private boolean isDecrypted
private long startXref
private boolean closed
private boolean isXRefStream
private ScratchFile scratchFile
private long highestXRefObjectNumber
public COSDocument()
public COSDocument(ScratchFile scratchFile)
scratchFile
- memory handler for buffering of PDF streamspublic COSStream createCOSStream()
public COSStream createCOSStream(COSDictionary dictionary)
dictionary
- the corresponding dictionarypublic COSObject getObjectByType(COSName type) throws java.io.IOException
type
- The type of the object.java.io.IOException
- If there is an error getting the objectpublic java.util.List<COSObject> getObjectsByType(java.lang.String type) throws java.io.IOException
type
- The type of the object.java.io.IOException
- If there is an error getting the objectpublic java.util.List<COSObject> getObjectsByType(COSName type) throws java.io.IOException
type
- The type of the object.java.io.IOException
- If there is an error getting the objectpublic COSObjectKey getKey(COSBase object)
object
- COS objectpublic void print()
public void setVersion(float versionValue)
versionValue
- The version of the PDF document.public float getVersion()
public void setDecrypted()
public boolean isDecrypted()
public boolean isEncrypted()
public COSDictionary getEncryptionDictionary()
public void setEncryptionDictionary(COSDictionary encDictionary)
encDictionary
- The encryption dictionary.public COSArray getDocumentID()
public void setDocumentID(COSArray id)
id
- The document id.public COSObject getCatalog() throws java.io.IOException
PDDocument.getDocumentCatalog()
instead.java.io.IOException
- If no catalog can be found.public java.util.List<COSObject> getObjects()
public COSDictionary getTrailer()
public void setTrailer(COSDictionary newTrailer)
newTrailer
- the document trailer dictionarypublic long getHighestXRefObjectNumber()
public void setHighestXRefObjectNumber(long highestXRefObjectNumber)
highestXRefObjectNumber
- The object number of the highest XRef stream.public java.lang.Object accept(ICOSVisitor visitor) throws java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- If there is an error close resources.public boolean isClosed()
protected void finalize() throws java.io.IOException
finalize
in class java.lang.Object
java.io.IOException
- if an error occurs while closing the temporary filespublic void setWarnMissingClose(boolean warn)
close()
method. If the PDF document is held in
a cache governed by soft references it is impossible to reliably close the document
before the warning is raised. By default, the warning is enabled.warn
- true enables the warning, false disables it.public void dereferenceObjectStreams() throws java.io.IOException
java.io.IOException
- If there is an error parsing the stream.public COSObject getObjectFromPool(COSObjectKey key) throws java.io.IOException
key
- The object key.java.io.IOException
- If there is an error getting the proxy object.public COSObject removeObject(COSObjectKey key)
key
- the object keypublic void addXRefTable(java.util.Map<COSObjectKey,java.lang.Long> xrefTableValues)
xrefTableValues
- xref table entries to be addedpublic java.util.Map<COSObjectKey,java.lang.Long> getXrefTable()
public void setStartXref(long startXrefValue)
startXrefValue
- the value for startXrefpublic long getStartXref()
public boolean isXRefStream()
public void setIsXRefStream(boolean isXRefStreamValue)
isXRefStreamValue
- the new value for isXRefStream