|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lowagie.text.pdf.PdfReader
Reads a PDF document and prepares it to import pages to our document. This class is thread safe; this means that a single instance can serve as many output documents as needed and can even be static.
Field Summary | |
---|---|
protected PRAcroForm |
acroForm
|
protected boolean |
acroFormParsed
|
private boolean |
appendable
Holds value of property appendable. |
protected PdfDictionary |
catalog
|
protected boolean |
consolidateNamedDestinations
|
protected PdfEncryption |
decrypt
|
protected boolean |
encrypted
|
(package private) static byte[] |
endobj
|
(package private) static byte[] |
endstream
|
protected int |
eofPos
|
private int |
fileLength
|
protected int |
freeXref
|
private boolean |
hybridXref
|
protected int |
lastXref
|
private IntHashtable |
newHits
|
protected boolean |
newXrefType
|
private int |
objGen
|
private int |
objNum
|
protected HashMap |
objStmMark
|
protected ArrayList |
pageInh
|
(package private) static PdfName[] |
pageInhCandidates
|
protected ArrayList |
pageRefs
|
protected ArrayList |
pages
|
protected byte[] |
password
|
protected char |
pdfVersion
|
protected int |
pValue
|
protected boolean |
rebuilt
|
protected int |
rValue
|
protected boolean |
sharedStreams
|
protected ArrayList |
strings
|
protected boolean |
tampered
|
protected PRTokeniser |
tokens
|
protected PdfDictionary |
trailer
|
private boolean[] |
visited
|
(package private) static int[] |
vpints
|
(package private) static PdfName[] |
vpnames
|
protected int[] |
xref
|
protected ArrayList |
xrefObj
|
Constructor Summary | |
---|---|
protected |
PdfReader()
|
|
PdfReader(byte[] pdfIn)
Reads and parses a PDF document. |
|
PdfReader(byte[] pdfIn,
byte[] ownerPassword)
Reads and parses a PDF document. |
|
PdfReader(InputStream is)
Reads and parses a PDF document. |
|
PdfReader(InputStream is,
byte[] ownerPassword)
Reads and parses a PDF document. |
|
PdfReader(PdfReader reader)
Creates an independent duplicate. |
|
PdfReader(String filename)
Reads and parses a PDF document. |
|
PdfReader(String filename,
byte[] ownerPassword)
Reads and parses a PDF document. |
|
PdfReader(URL url)
Reads and parses a PDF document. |
|
PdfReader(URL url,
byte[] ownerPassword)
Reads and parses a PDF document. |
Method Summary | |
---|---|
static byte[] |
ASCII85Decode(byte[] in)
Decodes a stream that has the ASCII85Decode filter. |
static byte[] |
ASCIIHexDecode(byte[] in)
Decodes a stream that has the ASCIIHexDecode filter. |
void |
consolidateNamedDestinations()
Replaces all the local named links with the actual destinations. |
int |
createFakeFontSubsets()
Finds all the fonts not subset but embedded and marks them as subset. |
static byte[] |
decodePredictor(byte[] in,
PdfObject dicPar)
|
protected static PdfDictionary |
duplicatePdfDictionary(PdfDictionary original,
PdfDictionary copy,
PdfReader newReader)
|
protected static PdfObject |
duplicatePdfObject(PdfObject original,
PdfReader newReader)
|
void |
eliminateSharedStreams()
Eliminates shared streams if they exist. |
private void |
ensureXrefSize(int size)
|
private boolean |
equalsArray(byte[] ar1,
byte[] ar2,
int size)
|
(package private) static boolean |
equalsn(byte[] a1,
byte[] a2)
|
(package private) static boolean |
existsName(PdfDictionary dic,
PdfName key,
PdfName value)
|
static byte[] |
FlateDecode(byte[] in)
Decodes a stream that has the FlateDecode filter. |
static byte[] |
FlateDecode(byte[] in,
boolean strict)
A helper to FlateDecode. |
AcroFields |
getAcroFields()
Gets a read-only version of AcroFields . |
PRAcroForm |
getAcroForm()
Returns the document's acroform, if it has one. |
Rectangle |
getBoxSize(int index,
String boxName)
Gets the box size. |
PdfDictionary |
getCatalog()
Returns the document's catalog. |
Rectangle |
getCropBox(int index)
Gets the crop box without taking rotation into account. |
(package private) PdfEncryption |
getDecrypt()
|
int |
getEofPos()
Gets the byte address of the %%EOF marker. |
int |
getFileLength()
Getter for property fileLength. |
(package private) static String |
getFontName(PdfDictionary dic)
|
HashMap |
getInfo()
Returns the content of the document information dictionary as a HashMap
of String . |
String |
getJavaScript()
Gets the global document JavaScript. |
String |
getJavaScript(RandomAccessFileOrArray file)
Gets the global document JavaScript. |
int |
getLastXref()
Gets the byte address of the last xref table. |
byte[] |
getMetadata()
Gets the XML metadata. |
private static PdfArray |
getNameArray(PdfObject obj)
|
HashMap |
getNamedDestination()
Gets all the named destinations as an HashMap . |
HashMap |
getNamedDestinationFromNames()
Gets the named destinations from the /Dests key in the catalog as an HashMap . |
HashMap |
getNamedDestinationFromStrings()
Gets the named destinations from the /Names key in the catalog as an HashMap . |
static Rectangle |
getNormalizedRectangle(PdfArray box)
Normalizes a Rectangle so that llx and lly are smaller than urx and ury. |
int |
getNumberOfPages()
Gets the number of pages in the document. |
byte[] |
getPageContent(int pageNum)
Gets the contents of the page. |
byte[] |
getPageContent(int pageNum,
RandomAccessFileOrArray file)
Gets the contents of the page. |
PdfDictionary |
getPageN(int pageNum)
Gets the dictionary that represents a page. |
PRIndirectReference |
getPageOrigRef(int pageNum)
Gets the page reference to this page. |
int |
getPageRotation(int index)
Gets the page rotation. |
(package private) int |
getPageRotation(PdfDictionary page)
|
Rectangle |
getPageSize(int index)
Gets the page size without taking rotation into account. |
Rectangle |
getPageSize(PdfDictionary page)
|
Rectangle |
getPageSizeWithRotation(int index)
Gets the page size, taking rotation into account. |
Rectangle |
getPageSizeWithRotation(PdfDictionary page)
|
static PdfObject |
getPdfObject(PdfObject obj)
Reads a PdfObject resolving an indirect reference
if needed. |
static PdfObject |
getPdfObject(PdfObject obj,
PdfObject parent)
|
protected PdfReaderInstance |
getPdfReaderInstance(PdfWriter writer)
|
char |
getPdfVersion()
Gets the PDF version. |
int |
getPermissions()
Gets the encryption permissions. |
RandomAccessFileOrArray |
getSafeFile()
Gets a new file instance of the original PDF document. |
static byte[] |
getStreamBytes(PRStream stream)
Get the content from a stream. |
static byte[] |
getStreamBytes(PRStream stream,
RandomAccessFileOrArray file)
Get the content from a stream. |
(package private) static String |
getSubsetPrefix(PdfDictionary dic)
|
PdfDictionary |
getTrailer()
Gets the trailer dictionary |
int |
getViewerPreferences()
|
int |
getXrefSize()
Gets the number of xref objects. |
boolean |
is128Key()
Returns true if the PDF has a 128 bit key encryption. |
boolean |
isAppendable()
Getter for property appendable. |
boolean |
isEncrypted()
Returns true if the PDF is encrypted. |
boolean |
isHybridXref()
Getter for property hybridXref. |
boolean |
isNewXrefType()
Getter for property newXrefType. |
boolean |
isRebuilt()
Checks if the document had errors and was rebuilt. |
boolean |
isTampered()
Checks if the document was changed. |
private void |
iterateBookmarks(PdfDictionary outline,
HashMap names)
|
protected void |
iteratePages(PRIndirectReference rpage)
|
(package private) static PdfObject |
killIndirect(PdfObject obj)
|
protected void |
killXref(PdfObject obj)
|
static byte[] |
LZWDecode(byte[] in)
Decodes a stream that has the LZWDecode filter. |
protected void |
popPageAttributes()
|
protected void |
PRSimpleRecursive(PdfObject obj)
|
protected void |
pushPageAttributes(PdfDictionary nodePages)
|
protected PdfArray |
readArray()
|
private void |
readDecryptedDocObj()
|
protected PdfDictionary |
readDictionary()
|
protected void |
readDocObj()
|
protected void |
readObjStm(PRStream stream,
IntHashtable map)
|
protected void |
readPages()
|
protected void |
readPdf()
|
protected PdfObject |
readPRObject()
|
protected void |
readXref()
|
protected PdfDictionary |
readXrefSection()
|
protected boolean |
readXRefStream(int ptr)
|
protected void |
rebuildXref()
|
void |
removeAnnotations()
Removes all the annotations and fields from the document. |
void |
removeFields()
Removes all the fields from the document. |
protected void |
removeUnusedNode(PdfObject obj,
boolean[] hits)
|
int |
removeUnusedObjects()
Removes all the unreachable objects. |
private static void |
replaceNamedDestination(PdfObject obj,
HashMap names)
|
void |
selectPages(List pagesToKeep)
Selects the pages to keep in the document. |
void |
selectPages(String ranges)
Selects the pages to keep in the document. |
void |
setAppendable(boolean appendable)
Setter for property appendable. |
void |
setPageContent(int pageNum,
byte[] content)
Sets the contents of the page. |
void |
setTampered(boolean tampered)
Sets the tampered state. |
void |
setViewerPreferences(int preferences)
|
static void |
setViewerPreferences(int preferences,
PdfDictionary catalog)
|
int |
shuffleSubsetNames()
Finds all the font subsets and changes the prefixes to some random values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
static final PdfName[] pageInhCandidates
static final PdfName[] vpnames
static final int[] vpints
static final byte[] endstream
static final byte[] endobj
protected PRTokeniser tokens
protected int[] xref
protected HashMap objStmMark
protected boolean newXrefType
protected ArrayList xrefObj
protected PdfDictionary trailer
protected ArrayList pages
protected PdfDictionary catalog
protected ArrayList pageRefs
protected PRAcroForm acroForm
protected boolean acroFormParsed
protected ArrayList pageInh
protected boolean encrypted
protected boolean rebuilt
protected int freeXref
protected boolean tampered
protected int lastXref
protected int eofPos
protected char pdfVersion
protected PdfEncryption decrypt
protected byte[] password
protected ArrayList strings
protected boolean sharedStreams
protected boolean consolidateNamedDestinations
protected int rValue
protected int pValue
private int objNum
private int objGen
private boolean[] visited
private IntHashtable newHits
private int fileLength
private boolean hybridXref
private boolean appendable
Constructor Detail |
protected PdfReader()
public PdfReader(String filename) throws IOException
filename
- the file name of the document
IOException
- on errorpublic PdfReader(String filename, byte[] ownerPassword) throws IOException
filename
- the file name of the documentownerPassword
- the password to read the document
IOException
- on errorpublic PdfReader(byte[] pdfIn) throws IOException
pdfIn
- the byte array with the document
IOException
- on errorpublic PdfReader(byte[] pdfIn, byte[] ownerPassword) throws IOException
pdfIn
- the byte array with the documentownerPassword
- the password to read the document
IOException
- on errorpublic PdfReader(URL url) throws IOException
url
- the URL of the document
IOException
- on errorpublic PdfReader(URL url, byte[] ownerPassword) throws IOException
url
- the URL of the documentownerPassword
- the password to read the document
IOException
- on errorpublic PdfReader(InputStream is, byte[] ownerPassword) throws IOException
is
- the InputStream
containing the document. The stream is read to the
end but is not closedownerPassword
- the password to read the document
IOException
- on errorpublic PdfReader(InputStream is) throws IOException
is
- the InputStream
containing the document. The stream is read to the
end but is not closed
IOException
- on errorpublic PdfReader(PdfReader reader)
reader
- the PdfReader
to duplicateMethod Detail |
public RandomAccessFileOrArray getSafeFile()
protected PdfReaderInstance getPdfReaderInstance(PdfWriter writer)
public int getNumberOfPages()
public PdfDictionary getCatalog()
public PRAcroForm getAcroForm()
public int getPageRotation(int index)
index
- the page number. The first page is 1
int getPageRotation(PdfDictionary page)
public Rectangle getPageSizeWithRotation(int index)
Rectangle
with the value of the /MediaBox and the /Rotate key.
index
- the page number. The first page is 1
Rectangle
public Rectangle getPageSizeWithRotation(PdfDictionary page)
public Rectangle getPageSize(int index)
index
- the page number. The first page is 1
public Rectangle getPageSize(PdfDictionary page)
public Rectangle getCropBox(int index)
index
- the page number. The first page is 1
public Rectangle getBoxSize(int index, String boxName)
index
- the page number. The first page is 1boxName
- the box name
public HashMap getInfo()
HashMap
of String
.
public static Rectangle getNormalizedRectangle(PdfArray box)
Rectangle
so that llx and lly are smaller than urx and ury.
box
- the original rectangle
Rectangle
protected void readPdf() throws IOException
IOException
private boolean equalsArray(byte[] ar1, byte[] ar2, int size)
private void readDecryptedDocObj() throws IOException
IOException
public static PdfObject getPdfObject(PdfObject obj)
PdfObject
resolving an indirect reference
if needed.
obj
- the PdfObject
to read
PdfObject
public static PdfObject getPdfObject(PdfObject obj, PdfObject parent)
protected void pushPageAttributes(PdfDictionary nodePages)
protected void popPageAttributes()
protected void iteratePages(PRIndirectReference rpage) throws IOException
IOException
protected void readPages() throws IOException
IOException
protected void PRSimpleRecursive(PdfObject obj) throws IOException
IOException
protected void readDocObj() throws IOException
IOException
protected void readObjStm(PRStream stream, IntHashtable map) throws IOException
IOException
static PdfObject killIndirect(PdfObject obj)
private void ensureXrefSize(int size)
protected void readXref() throws IOException
IOException
protected PdfDictionary readXrefSection() throws IOException
IOException
protected boolean readXRefStream(int ptr) throws IOException
IOException
protected void rebuildXref() throws IOException
IOException
protected PdfDictionary readDictionary() throws IOException
IOException
protected PdfArray readArray() throws IOException
IOException
protected PdfObject readPRObject() throws IOException
IOException
public static byte[] FlateDecode(byte[] in)
in
- the input data
public static byte[] decodePredictor(byte[] in, PdfObject dicPar)
public static byte[] FlateDecode(byte[] in, boolean strict)
in
- the input datastrict
- true
to read a correct stream. false
to try to read a corrupted stream
public static byte[] ASCIIHexDecode(byte[] in)
in
- the input data
public static byte[] ASCII85Decode(byte[] in)
in
- the input data
public static byte[] LZWDecode(byte[] in)
in
- the input data
public boolean isRebuilt()
public PdfDictionary getPageN(int pageNum)
pageNum
- the page number. 1 is the first
public PRIndirectReference getPageOrigRef(int pageNum)
pageNum
- the page number. 1 is the first
public byte[] getPageContent(int pageNum, RandomAccessFileOrArray file) throws IOException
pageNum
- the page number. 1 is the firstfile
- the location of the PDF document
IOException
- on errorpublic byte[] getPageContent(int pageNum) throws IOException
pageNum
- the page number. 1 is the first
IOException
- on errorprotected void killXref(PdfObject obj)
public void setPageContent(int pageNum, byte[] content) throws IOException
content
- the new page contentpageNum
- the page number. 1 is the first
IOException
- on errorpublic static byte[] getStreamBytes(PRStream stream, RandomAccessFileOrArray file) throws IOException
stream
- the streamfile
- the location where the stream is
IOException
- on errorpublic static byte[] getStreamBytes(PRStream stream) throws IOException
stream
- the stream
IOException
- on errorpublic void eliminateSharedStreams()
public boolean isTampered()
true
if the document was changed,
false
otherwisepublic void setTampered(boolean tampered)
tampered
- the tampered statepublic byte[] getMetadata() throws IOException
IOException
- on errorpublic int getLastXref()
public int getXrefSize()
public int getEofPos()
public char getPdfVersion()
public boolean isEncrypted()
true
if the PDF is encrypted.
true
if the PDF is encryptedpublic int getPermissions()
PdfWriter.setEncryption()
.
public boolean is128Key()
true
if the PDF has a 128 bit key encryption.
true
if the PDF has a 128 bit key encryptionpublic PdfDictionary getTrailer()
PdfEncryption getDecrypt()
static boolean equalsn(byte[] a1, byte[] a2)
static boolean existsName(PdfDictionary dic, PdfName key, PdfName value)
static String getFontName(PdfDictionary dic)
static String getSubsetPrefix(PdfDictionary dic)
public int shuffleSubsetNames()
public int createFakeFontSubsets()
private static PdfArray getNameArray(PdfObject obj)
public HashMap getNamedDestination()
HashMap
. The key is the name
and the value is the destinations array.
public HashMap getNamedDestinationFromNames()
HashMap
. The key is the name
and the value is the destinations array.
public HashMap getNamedDestinationFromStrings()
HashMap
. The key is the name
and the value is the destinations array.
private static void replaceNamedDestination(PdfObject obj, HashMap names)
public void removeFields()
public void removeAnnotations()
private void iterateBookmarks(PdfDictionary outline, HashMap names)
public void consolidateNamedDestinations()
protected static PdfDictionary duplicatePdfDictionary(PdfDictionary original, PdfDictionary copy, PdfReader newReader)
protected static PdfObject duplicatePdfObject(PdfObject original, PdfReader newReader)
protected void removeUnusedNode(PdfObject obj, boolean[] hits)
public int removeUnusedObjects()
public AcroFields getAcroFields()
AcroFields
.
AcroFields
public String getJavaScript(RandomAccessFileOrArray file) throws IOException
file
- the document file
IOException
- on errorpublic String getJavaScript() throws IOException
IOException
- on errorpublic void selectPages(String ranges)
ranges
- the comma separated ranges as described in SequenceList
public void selectPages(List pagesToKeep)
List
of Integer
. The page ordering can be changed but
no page repetitions are allowed.
pagesToKeep
- the pages to keep in the documentpublic static void setViewerPreferences(int preferences, PdfDictionary catalog)
public void setViewerPreferences(int preferences)
public int getViewerPreferences()
public boolean isAppendable()
public void setAppendable(boolean appendable)
appendable
- New value of property appendable.public boolean isNewXrefType()
public int getFileLength()
public boolean isHybridXref()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |