org.icepdf.core.pobjects
Class PTrailer

java.lang.Object
  extended by org.icepdf.core.pobjects.Dictionary
      extended by org.icepdf.core.pobjects.PTrailer

public class PTrailer
extends Dictionary

The trailer of a PDF file enables an application reading the file to quickly find the cross-reference table and certain special objects. Applications should read a PDF file from its end. The last line of the file contains only the end-of-file marker, %%EOF.

A document can have more then one trailer reference. It is important to use the addTrailer() method if a subsequent trailer is found, or the addPreviousTrailer() method if a previous trailer is found, depending on if the PDF file is being read linearly, or via random access seeking.

If the Prev key entry is present then the document has more then one cross-reference section. There is a numerical value, which is typically associated with the trailer, that comes after startxref, and before %%EOF. It is byte offset from the beginning of the file to the beginning of the last cross-reference section.

In a regular PDF, it's the address of the current xref table. In a linearized PDF, it's the address of the xref table at the file beginning, or zero. In an updated PDF, it's the address of the current xref table. In all cases, the LastCrossReferenceSection field, at the end of the PDF file, points to the byte offset from the beginning of the file, of the "last" xref section, which means the xref section with the highest precedence. For each xref section, its following trailer section has a Prev field, which points to the byte offset from the beginning of the file, of the xref section with one less degree of precedence.

Since:
1.1

Field Summary
 
Fields inherited from class org.icepdf.core.pobjects.Dictionary
entries, inited, isDeleted, isNew, library, SUBTYPE_KEY, TYPE_KEY
 
Constructor Summary
PTrailer(Library library, java.util.Hashtable dictionary, CrossReference xrefTable, CrossReference xrefStream)
          Create a new PTrailer object
 
Method Summary
protected  void addNextTrailer(PTrailer nextTrailer)
          Add the trailer dictionary to the current trailer object's dictionary.
protected  void addPreviousTrailer(PTrailer previousTrailer)
           
protected  CrossReference getCrossReferenceStream()
          Gets the cross reference stream.
protected  CrossReference getCrossReferenceTable()
          Gets the cross reference table.
 java.util.Hashtable getDictionary()
          Get the trailer object's dictionary.
 java.util.Hashtable getEncrypt()
          The document's encryption dictionary

Required : if document is encrypted; PDF 1.1

 java.util.Vector getID()
          A vector of two strings constituting a file identifier

Optional : PDF 1.1.

 PInfo getInfo()
          The document's information dictionary

Optional : must be an indirect reference.

 int getNumberOfObjects()
          Gets the total number of entries in the file's cross-reference table, as defined by the combination of the original section and all updated sections.
 long getPosition()
           
 long getPrev()
          Gets the byte offset from the beginning of the file to the beginning of the previous cross-reference section.
protected  CrossReference getPrimaryCrossReference()
          Depending on if the PDF file is version 1.4 or before, or 1.5 or after, it may have a cross reference table, or cross reference stream, or both.
 Catalog getRootCatalog()
          Gets the Catalog entry for this PDF document.
 Reference getRootCatalogReference()
          Gets the catalog reference for the PDF document contained in the file.
protected  void loadXRefStmIfApplicable()
           
protected  void onDemandLoadAndSetupPreviousTrailer()
           
 void setPosition(long pos)
          After this PTrailer is parsed, we store it's location within the PDF here, for future use.
 java.lang.String toString()
          Returns a summary of the PTrailer dictionary values.
 
Methods inherited from class org.icepdf.core.pobjects.Dictionary
getEntries, getFloat, getInt, getLibrary, getNumber, getObject, getObject, getPObjectReference, init, isDeleted, isNew, setDeleted, setNew, setPObjectReference
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PTrailer

public PTrailer(Library library,
                java.util.Hashtable dictionary,
                CrossReference xrefTable,
                CrossReference xrefStream)
Create a new PTrailer object

Parameters:
dictionary - dictionary associated with the trailer
Method Detail

getNumberOfObjects

public int getNumberOfObjects()
Gets the total number of entries in the file's cross-reference table, as defined by the combination of the original section and all updated sections. Equivalently, this value is 1 greater than the highest object number used in the file.

Required : must not be an indirect reference

Returns:
total number of entries in the file's cross-reference table

getPrev

public long getPrev()
Gets the byte offset from the beginning of the file to the beginning of the previous cross-reference section.

(Present only if the file has more than one cross-reference section; must not be an indirect reference)

Returns:
byte offset from beginning of the file to the beginning of the previous cross-reference section

getPrimaryCrossReference

protected CrossReference getPrimaryCrossReference()
Depending on if the PDF file is version 1.4 or before, or 1.5 or after, it may have a cross reference table, or cross reference stream, or both. If there are both, then the cross reference table has precedence.

Returns:
the cross reference object with the highest precedence, for this trailer

getCrossReferenceTable

protected CrossReference getCrossReferenceTable()
Gets the cross reference table.

Returns:
cross reference table object; null, if one does not exist.

getCrossReferenceStream

protected CrossReference getCrossReferenceStream()
Gets the cross reference stream.

Returns:
cross reference stream object; null, if one does not exist.

getRootCatalogReference

public Reference getRootCatalogReference()
Gets the catalog reference for the PDF document contained in the file.

Required : must not be an indirect reference

Returns:
reference number of catalog reference.

getRootCatalog

public Catalog getRootCatalog()
Gets the Catalog entry for this PDF document.

Returns:
Catalog entry.

getEncrypt

public java.util.Hashtable getEncrypt()
The document's encryption dictionary

Required : if document is encrypted; PDF 1.1

Returns:
encryption dictionary

getInfo

public PInfo getInfo()
The document's information dictionary

Optional : must be an indirect reference.

Returns:
information dictionary

getID

public java.util.Vector getID()
A vector of two strings constituting a file identifier

Optional : PDF 1.1.

Returns:
vector containing constituting file identifier

getPosition

public long getPosition()
Returns:
The position in te file where this trailer is located

setPosition

public void setPosition(long pos)
After this PTrailer is parsed, we store it's location within the PDF here, for future use.


addNextTrailer

protected void addNextTrailer(PTrailer nextTrailer)
Add the trailer dictionary to the current trailer object's dictionary.

Parameters:
nextTrailer - document trailer object

addPreviousTrailer

protected void addPreviousTrailer(PTrailer previousTrailer)

onDemandLoadAndSetupPreviousTrailer

protected void onDemandLoadAndSetupPreviousTrailer()

loadXRefStmIfApplicable

protected void loadXRefStmIfApplicable()

getDictionary

public java.util.Hashtable getDictionary()
Get the trailer object's dictionary.

Returns:
dictionary

toString

public java.lang.String toString()
Returns a summary of the PTrailer dictionary values.

Overrides:
toString in class Dictionary
Returns:
dictionary values.