Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.pdfbox.cos
Class COSDocument

    java.lang.Object
      org.pdfbox.cos.COSBase
          org.pdfbox.cos.COSDocument

All 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.26 $
Author:
  Ben Litchfield (ben@csh.rit.edu)

Constructor Summary
`COSDocument()` Constructor.
`COSDocument(File scratchDir)` Constructor that will create a create a scratch file in the following directory.
`COSDocument(RandomAccessFile 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(COSName type)` This will get the first dictionary object by type.
`COSObject` | `getObjectByType(String 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(COSName type)` This will get a dictionary object by type.
`List` | `getObjectsByType(String type)` This will get all dictionary objects by type.
`RandomAccessFile` | `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
`getCOSObject, getFilterManager`

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### COSDocument

    public COSDocument()
                throws IOException

  Constructor. Uses the java.io.tmpdir value to create a file to store the streams.

Throws:
  `IOException` - If there is an error creating the tmp file.

### 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.
Throws:
  `IOException` - If there is an error creating the tmp file.

### COSDocument

    public COSDocument(RandomAccessFile 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 Detail

### getScratchFile

    public RandomAccessFile getScratchFile()

  This will get the scratch file for this document.

  Returns:
    The scratch file.

### 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.

### 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.

### print

    public void print()

  This will print contents to stdout.

### setVersion

    public void setVersion(float versionValue)

  This will set the version of this PDF document.

  Parameters:
    `versionValue` - The version of the PDF document.

### 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.

### 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.

### 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.

### getDocumentID

    public COSArray getDocumentID()

  This will get the document ID.

  Returns:
    The document id.

### setDocumentID

    public void setDocumentID(COSArray id)

  This will set the document ID.

  Parameters:
    `id` - The document id.

### 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
  Throws:
    `IOException` - If no catalog can be found.

### getObjects

    public List getObjects()

  This will get a list of all available objects.

  Returns:
    A list of all objects.

### getTrailer

    public COSDictionary getTrailer()

  This will get the document trailer.

  Returns:
    the document trailer dict

### 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

### accept

    public Object accept(ICOSVisitor visitor)
                  throws COSVisitorException

  visitor pattern double dispatch method.

  Specified by:
    `accept` in class `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.

### close

    public void close()
               throws IOException

  This will close all storage and delete the tmp files.

  Throws:
    `IOException` - If there is an error close resources.

### finalize

    protected void finalize()

  The sole purpose of this is to inform a client of PDFBox that they did not close the document.

### getHeaderString

    public String getHeaderString()

  Returns:
    Returns the headerString.

### setHeaderString

    public void setHeaderString(String header)

  Parameters:
    `header` - The headerString to set.

### 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.

  Throws:
    `IOException` - If there is an error parsing the stream.

### 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.
  Throws:
    `IOException` - If there is an error adding the object.

### 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.
  Throws:
    `IOException` - If there is an error getting the proxy object.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD