org.pdfbox.cos

Class COSDocument

Implemented Interfaces:
COSObjectable

public class COSDocument
extends COSBase

This is the in-memory representation of the PDF document. You need to call close() on this object when you are done using it!!
Version:
$Revision: 1.28 $
Author:
Ben Litchfield

Constructor Summary

COSDocument()
Constructor.
COSDocument(File scratchDir)
Constructor that will create a create a scratch file in the following directory.
COSDocument(RandomAccess file)
Constructor that will use the following random access file for storage of the PDF streams.

Method Summary

Object
accept(ICOSVisitor visitor)
visitor pattern double dispatch method.
COSObject
addObject(COSObject obj)
This will add an object to this document.
void
close()
This will close all storage and delete the tmp files.
void
dereferenceObjectStreams()
This method will search the list of objects for types of ObjStm.
protected void
finalize()
The sole purpose of this is to inform a client of PDFBox that they did not close the document.
COSObject
getCatalog()
This will get the document catalog.
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.
String
getHeaderString()
COSObject
getObjectByType(String type)
This will get the first dictionary object by type.
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.
List
getObjects()
This will get a list of all available objects.
List
getObjectsByType(String type)
This will get all dictionary objects by type.
List
getObjectsByType(COSName type)
This will get a dictionary object by type.
RandomAccess
getScratchFile()
This will get the scratch file for this document.
COSDictionary
getTrailer()
This will get the document trailer.
float
getVersion()
This will get the version of this PDF document.
boolean
isEncrypted()
This will tell if this is an encrypted document.
void
print()
This will print contents to stdout.
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 encypting the document.
void
setHeaderString(String header)
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 version of this PDF document.

Methods inherited from class org.pdfbox.cos.COSBase

accept, getCOSObject, getFilterManager

Constructor Details

COSDocument

public COSDocument()
            throws IOException
Constructor. Uses the java.io.tmpdir value to create a file to store the streams.

COSDocument

public COSDocument(File scratchDir)
            throws IOException
Constructor that will create a create a scratch file in the following directory.
Parameters:
scratchDir - The directory to store a scratch file.

COSDocument

public COSDocument(RandomAccess file)
Constructor that will use the following random access file for storage of the PDF streams. The client of this method is responsible for deleting the storage if necessary that this file will write to. The close method will close the file though.
Parameters:
file - The random access file to use for storage.

Method Details

accept

public Object accept(ICOSVisitor visitor)
            throws COSVisitorException
visitor pattern double dispatch method.
Overrides:
accept in interface COSBase
Parameters:
visitor - The object to notify when visiting this object.
Returns:
any object, depending on the visitor implementation, or null
Throws:
COSVisitorException - If an error occurs while visiting this object.

addObject

public COSObject addObject(COSObject obj)
            throws IOException
This will add an object to this document. the method checks if obj is already present as there may be cyclic dependencies
Parameters:
obj - The object to add to the document.
Returns:
The object that was actually added to this document, if an object reference already existed then that will be returned.

close

public void close()
            throws IOException
This will close all storage and delete the tmp files.

dereferenceObjectStreams

public void dereferenceObjectStreams()
            throws IOException
This method will search the list of objects for types of ObjStm. If it finds them then it will parse out all of the objects from the stream that is contains.

finalize

protected void finalize()
The sole purpose of this is to inform a client of PDFBox that they did not close the document.

getCatalog

public COSObject getCatalog()
            throws IOException
This will get the document catalog. Maybe this should move to an object at PDFEdit level
Returns:
catalog is the root of all document activities

getDocumentID

public COSArray getDocumentID()
This will get the document ID.
Returns:
The document id.

getEncryptionDictionary

public COSDictionary getEncryptionDictionary()
This will get the encryption dictionary if the document is encrypted or null if the document is not encrypted.
Returns:
The encryption dictionary.

getHeaderString

public String getHeaderString()
Returns:
Returns the headerString.

getObjectByType

public COSObject getObjectByType(String type)
This will get the first dictionary object by type.
Parameters:
type - The type of the object.
Returns:
This will return an object with the specified type.

getObjectByType

public COSObject getObjectByType(COSName type)
This will get the first dictionary object by type.
Parameters:
type - The type of the object.
Returns:
This will return an object with the specified type.

getObjectFromPool

public COSObject getObjectFromPool(COSObjectKey key)
            throws IOException
This will get an object from the pool.
Parameters:
key - The object key.
Returns:
The object in the pool or a new one if it has not been parsed yet.

getObjects

public List getObjects()
This will get a list of all available objects.
Returns:
A list of all objects.

getObjectsByType

public List getObjectsByType(String type)
This will get all dictionary objects by type.
Parameters:
type - The type of the object.
Returns:
This will return an object with the specified type.

getObjectsByType

public List getObjectsByType(COSName type)
This will get a dictionary object by type.
Parameters:
type - The type of the object.
Returns:
This will return an object with the specified type.

getScratchFile

public RandomAccess getScratchFile()
This will get the scratch file for this document.
Returns:
The scratch file.

getTrailer

public COSDictionary getTrailer()
This will get the document trailer.
Returns:
the document trailer dict

getVersion

public float getVersion()
This will get the version of this PDF document.
Returns:
This documents version.

isEncrypted

public boolean isEncrypted()
This will tell if this is an encrypted document.
Returns:
true If this document is encrypted.

print

public void print()
This will print contents to stdout.

setDocumentID

public void setDocumentID(COSArray id)
This will set the document ID.
Parameters:
id - The document id.

setEncryptionDictionary

public void setEncryptionDictionary(COSDictionary encDictionary)
This will set the encryption dictionary, this should only be called when encypting the document.
Parameters:
encDictionary - The encryption dictionary.

setHeaderString

public void setHeaderString(String header)
Parameters:
header - The headerString to set.

setTrailer

public void setTrailer(COSDictionary newTrailer)
// MIT added, maybe this should not be supported as trailer is a persistence construct. This will set the document trailer.
Parameters:
newTrailer - the document trailer dictionary

setVersion

public void setVersion(float versionValue)
This will set the version of this PDF document.
Parameters:
versionValue - The version of the PDF document.