Top Description Inners Fields Constructors Methods
org.apache.pdfbox.pdfparser

public Class XrefTrailerResolver

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collections, .HashMap, .HashSet, .List, .Map, .Set, .SortedSet, .TreeSet, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.cos.COSDictionary, .COSName, .COSObjectKey

This class will collect all XRef/trailer objects and creates correct xref/trailer information after all objects are read using startxref and 'Prev' information (unused XRef/trailer objects are discarded). In case of missing startxref or wrong startxref pointer all XRef/trailer objects are used to create xref table / trailer dictionary in order they occur. For each new xref object/XRef stream method nextXrefObj(long, XRefType) must be called with start byte position. All following calls to setXRef(COSObjectKey, long) or setTrailer(COSDictionary) will add the data for this byte position. After all objects are parsed the startxref position must be provided using setStartxref(long). This is used to build the chain of active xref/trailer objects used for creating document trailer and xref table.
Author
Timo Böhme

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
XrefTrailerResolver.XrefTrailerObj

A class which represents a xref/trailer object.

public static enum
XrefTrailerResolver.XRefType

The XRefType of a trailer.

Field Summary

Modifier and TypeField and Description
private final Map<Long, XrefTrailerResolver.XrefTrailerObj>
private XrefTrailerResolver.XrefTrailerObj
private static final Log
LOG

Log instance.

private XrefTrailerResolver.XrefTrailerObj

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Set<Long>

Returns:

set of object numbers referenced for given object stream or null if setStartxref(long) was not called before so that no resolved xref table exists
getContainedObjectNumbers
(final int
object number of object stream for which contained object numbers should be returned
objstmObjNr
)

Returns object numbers which are referenced as contained in object stream with specified object number.

public COSDictionary

Returns:

the current trailer.
getCurrentTrailer
()

Returns the trailer last set by setTrailer(COSDictionary).

public final COSDictionary

Returns:

the first trailer or null
getFirstTrailer
()

Returns the first trailer if at least one exists.

public final COSDictionary

Returns:

the last trailer ir null
getLastTrailer
()

Returns the last trailer if at least one exists.

public COSDictionary

Returns:

the trailer if available
getTrailer
()

Gets the resolved trailer.

public final int

Returns:

the count of trailers.
getTrailerCount
()

Returns the count of trailers.

public Map<COSObjectKey, Long>

Returns:

the xrefTable if available
getXrefTable
()

Gets the resolved xref table.

public XrefTrailerResolver.XRefType

Returns:

the XRefType or null.
getXrefType
()

Returns the XRefTxpe of the resolved trailer.

public void
nextXrefObj(final long
the offset to start at
startBytePos
,
XrefTrailerResolver.XRefType
the type of the Xref object
type
)

Signals that a new XRef object (table or stream) starts.

protected void
reset()

Reset all data so that it can be used to rebuild the trailer.

public void
setStartxref(long
starting position of the first XRef
startxrefBytePosValue
)

Sets the byte position of the first XRef (has to be called after very last startxref was read).

public void
setTrailer(COSDictionary
the current document trailer dictionary
trailer
)

Adds trailer information for current XRef object.

public void
setXRef(COSObjectKey
The objkey, with id and gen numbers
objKey
,
long
The byte offset in this file
offset
)

Populate XRef HashMap of current XRef object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bytePosToXrefMapback to summary
private final Map<Long, XrefTrailerResolver.XrefTrailerObj> bytePosToXrefMap
curXrefTrailerObjback to summary
private XrefTrailerResolver.XrefTrailerObj curXrefTrailerObj
LOGback to summary
private static final Log LOG

Log instance.

resolvedXrefTrailerback to summary
private XrefTrailerResolver.XrefTrailerObj resolvedXrefTrailer

Constructor Detail

XrefTrailerResolverback to summary
public XrefTrailerResolver()

Method Detail

getContainedObjectNumbersback to summary
public Set<Long> getContainedObjectNumbers(final int objstmObjNr)

Returns object numbers which are referenced as contained in object stream with specified object number. This will scan resolved xref table for all entries having negated stream object number as value.

Parameters
objstmObjNr:int

object number of object stream for which contained object numbers should be returned

Returns:Set<Long>

set of object numbers referenced for given object stream or null if setStartxref(long) was not called before so that no resolved xref table exists

getCurrentTrailerback to summary
public COSDictionary getCurrentTrailer()

Returns the trailer last set by setTrailer(COSDictionary).

Returns:COSDictionary

the current trailer.

getFirstTrailerback to summary
public final COSDictionary getFirstTrailer()

Returns the first trailer if at least one exists.

Returns:COSDictionary

the first trailer or null

getLastTrailerback to summary
public final COSDictionary getLastTrailer()

Returns the last trailer if at least one exists.

Returns:COSDictionary

the last trailer ir null

getTrailerback to summary
public COSDictionary getTrailer()

Gets the resolved trailer. Might return null in case setStartxref(long) was not called before.

Returns:COSDictionary

the trailer if available

getTrailerCountback to summary
public final int getTrailerCount()

Returns the count of trailers.

Returns:int

the count of trailers.

getXrefTableback to summary
public Map<COSObjectKey, Long> getXrefTable()

Gets the resolved xref table. Might return null in case setStartxref(long) was not called before.

Returns:Map<COSObjectKey, Long>

the xrefTable if available

getXrefTypeback to summary
public XrefTrailerResolver.XRefType getXrefType()

Returns the XRefTxpe of the resolved trailer.

Returns:XrefTrailerResolver.XRefType

the XRefType or null.

nextXrefObjback to summary
public void nextXrefObj(final long startBytePos, XrefTrailerResolver.XRefType type)

Signals that a new XRef object (table or stream) starts.

Parameters
startBytePos:long

the offset to start at

type:XrefTrailerResolver.XRefType

the type of the Xref object

resetback to summary
protected void reset()

Reset all data so that it can be used to rebuild the trailer.

setStartxrefback to summary
public void setStartxref(long startxrefBytePosValue)

Sets the byte position of the first XRef (has to be called after very last startxref was read). This is used to resolve chain of active XRef/trailer. In case startxref position is not found we output a warning and use all XRef/trailer objects combined in byte position order. Thus for incomplete PDF documents with missing startxref one could call this method with parameter value -1.

Parameters
startxrefBytePosValue:long

starting position of the first XRef

setTrailerback to summary
public void setTrailer(COSDictionary trailer)

Adds trailer information for current XRef object.

Parameters
trailer:COSDictionary

the current document trailer dictionary

setXRefback to summary
public void setXRef(COSObjectKey objKey, long offset)

Populate XRef HashMap of current XRef object. Will add an Xreftable entry that maps ObjectKeys to byte offsets in the file.

Parameters
objKey:COSObjectKey

The objkey, with id and gen numbers

offset:long

The byte offset in this file

org.apache.pdfbox.pdfparser back to summary

private Class XrefTrailerResolver.XrefTrailerObj

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.pdfbox.pdfparser.XrefTrailerResolver.XrefTrailerObj

A class which represents a xref/trailer object.

Field Summary

Modifier and TypeField and Description
protected COSDictionary
private final Map<COSObjectKey, Long>
private XrefTrailerResolver.XRefType

Constructor Summary

AccessConstructor and Description
private
XrefTrailerObj()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

trailerback to summary
protected COSDictionary trailer
xrefTableback to summary
private final Map<COSObjectKey, Long> xrefTable
xrefTypeback to summary
private XrefTrailerResolver.XRefType xrefType

Constructor Detail

XrefTrailerObjback to summary
private XrefTrailerObj()

Default constructor.

Method Detail

resetback to summary
public void reset()
org.apache.pdfbox.pdfparser back to summary

public final Enum XrefTrailerResolver.XRefType

extends Enum<XrefTrailerResolver.XRefType>
Class Inheritance

The XRefType of a trailer.

Field Summary

Modifier and TypeField and Description
public static final XrefTrailerResolver.XRefType
STREAM

XRef stream type.

public static final XrefTrailerResolver.XRefType
TABLE

XRef table type.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static XrefTrailerResolver.XRefType
public static XrefTrailerResolver.XRefType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

STREAMback to summary
public static final XrefTrailerResolver.XRefType STREAM

XRef stream type.

TABLEback to summary
public static final XrefTrailerResolver.XRefType TABLE

XRef table type.

Constructor Detail

XRefTypeback to summary
private XRefType()

Method Detail

valueOfback to summary
public static XrefTrailerResolver.XRefType valueOf(String name)
valuesback to summary
public static XrefTrailerResolver.XRefType[] values()