public class Pdf
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected PjObjectVector |
_objects |
protected java.util.Hashtable |
_trailer |
Constructor and Description |
---|
Pdf()
Creates an empty PDF document.
|
Pdf(java.lang.String filename)
Creates a PDF document from an existing PDF file.
|
Modifier and Type | Method and Description |
---|---|
void |
addToPage(PjPage page,
int objectNumber)
Adds a PjObject to a page in this PDF document.
|
private static void |
adjustTextMatrixX(java.util.Vector pmVector,
float rectWidth) |
int |
appendPage(int objectNumber)
Appends a PjPage to the end of this PDF document.
|
void |
appendPdfDocument(Pdf pdf)
Appends the pages of a PDF document to this document.
|
private static void |
clearTextMatrixX(java.util.Vector pmVector) |
private void |
createEmpty() |
int |
deletePage(int pageNumber)
Deletes a page in this document by page number.
|
private int |
findPage(int pageNumber,
int objectNumber,
PjPages parentPages,
IntCounter counter,
boolean delete) |
int |
getCatalog()
Looks up the Catalog object in this document.
|
PjDictionary |
getEncryptDictionary()
Looks up the Encrypt dictionary within this document's trailer.
|
java.util.Vector |
getFields() |
private void |
getFieldsAddField(java.util.Vector fieldList,
PjReference fieldRef) |
PjReference |
getInfoDictionary()
Looks up the Info dictionary within this document's trailer.
|
int |
getMaxObjectNumber()
Returns the largest object number in the list of registered
PjObjects.
|
PjObject |
getObject(int objectNumber)
Looks up a PjObject by its object number.
|
int |
getPage(int pageNumber)
Looks up a page in this document by page number.
|
int |
getPageCount()
Determines the number of pages in this PDF document.
|
int |
getRootPages()
Looks up the root Pages object of this document's Pages tree.
|
PjDictionary |
inheritFieldAttributes(PjDictionary node)
Returns a clone of a field node such that all inherited
attributes of the given field node are made explicit.
|
private void |
inheritFieldAttributesCollapse(PjName name,
java.util.Hashtable ht,
PjDictionary newNode,
PjDictionary parent) |
PjPagesNode |
inheritPageAttributes(PjPagesNode node)
Returns a clone of a pages node such that all inherited
attributes of the given pages node are made explicit.
|
private void |
inheritPageAttributesCollapse(PjName name,
java.util.Hashtable ht,
PjPagesNode newNode,
PjPagesNode parent) |
private void |
init() |
private void |
readFromFile(java.lang.String filename) |
int |
registerObject(PjObject obj)
Registers a PjObject within this PDF document.
|
void |
registerObject(PjObject obj,
int objectNumber)
Registers a PjObject within this PDF document using a
specified object number.
|
private static void |
replaceTextData(java.util.Vector pmVector,
PjString oldText,
PjString newText) |
PjObject |
resolve(PjObject obj)
Dereferences a PjObject if it is a PjReference.
|
void |
setEncryptDictionary(PjDictionary dict)
Sets the Encrypt dictionary within this document's trailer.
|
void |
setEncryptDictionary(PjReference ref)
Sets the Encrypt dictionary within this document's trailer.
|
void |
setInfoDictionary(PjReference ref)
Sets the Info dictionary within this document's trailer.
|
void |
updateFieldValue(PjDictionary origField,
PjDictionary field,
java.lang.String value) |
void |
writeToFile(java.lang.String filename)
Writes this PDF document to a file in PDF format.
|
void |
writeToStream(java.io.OutputStream os)
Writes this PDF document to a stream in PDF format.
|
protected PjObjectVector _objects
protected java.util.Hashtable _trailer
public Pdf()
public Pdf(java.lang.String filename) throws java.io.IOException, PjException
filename
- the name of the PDF file to read.java.io.IOException
- if an I/O error occurs.PjException
- if a PDF error occurs.public void writeToFile(java.lang.String filename) throws java.io.IOException
filename
- the name of the PDF file to create.java.io.IOException
- if an I/O error occurs.public void writeToStream(java.io.OutputStream os) throws java.io.IOException
os
- the stream to write to.java.io.IOException
- if an I/O error occurs.public int registerObject(PjObject obj)
obj
- the PjObject to register.public void registerObject(PjObject obj, int objectNumber)
obj
- the PjObject to register.objectNumber
- the object number to register obj under.public void addToPage(PjPage page, int objectNumber) throws InvalidPdfObjectException
page
- the page object to add to.objectNumber
- the object number of the PjObject to add.InvalidPdfObjectException
- if an invalid object
type is encountered.public PjObject getObject(int objectNumber)
objectNumber
- the object number of the PjObject to retrieve.public PjObject resolve(PjObject obj)
obj
- the PjObject to dereference.public int getPageCount() throws InvalidPdfObjectException
InvalidPdfObjectException
- if an invalid object
type is encountered.private int findPage(int pageNumber, int objectNumber, PjPages parentPages, IntCounter counter, boolean delete) throws InvalidPdfObjectException
InvalidPdfObjectException
public int getPage(int pageNumber) throws java.lang.IndexOutOfBoundsException, InvalidPdfObjectException
pageNumber
- the page number. Pages are numbered
starting with 1.java.lang.IndexOutOfBoundsException
- if an invalid page
number was given.InvalidPdfObjectException
- if an invalid object
type is encountered.public int deletePage(int pageNumber) throws java.lang.IndexOutOfBoundsException, InvalidPdfObjectException
pageNumber
- the page number. Pages are numbered
starting with 1.java.lang.IndexOutOfBoundsException
- if an invalid page
number was given.InvalidPdfObjectException
- if an invalid object
type is encountered.public int appendPage(int objectNumber)
objectNumber
- the object number of the PjPage to append.public void appendPdfDocument(Pdf pdf) throws InvalidPdfObjectException
pdf
- the PDF document to append.InvalidPdfObjectException
- if an invalid object
type is encountered in either document.public int getCatalog() throws InvalidPdfObjectException
InvalidPdfObjectException
- if an invalid object
type is encountered.public int getRootPages() throws InvalidPdfObjectException
InvalidPdfObjectException
- if an invalid object
type is encountered.public PjReference getInfoDictionary() throws InvalidPdfObjectException
InvalidPdfObjectException
- if the Info field in
the trailer is not a reference (PjReference) object.public void setInfoDictionary(PjReference ref)
ref
- a reference to the Info dictionary.public PjDictionary getEncryptDictionary() throws InvalidPdfObjectException
InvalidPdfObjectException
- if the Encrypt field in
the trailer is not a dictionary (PjDictionary) object.public void setEncryptDictionary(PjReference ref)
ref
- a reference to the Encrypt dictionary.public void setEncryptDictionary(PjDictionary dict)
dict
- the Encrypt dictionary.public PjPagesNode inheritPageAttributes(PjPagesNode node) throws InvalidPdfObjectException
node
- a pages node for which inherited attributes are
to be retrieved.InvalidPdfObjectException
- if an invalid object
type is encountered.public PjDictionary inheritFieldAttributes(PjDictionary node) throws InvalidPdfObjectException
node
- a field node for which inherited attributes are
to be retrieved.InvalidPdfObjectException
- if an invalid object
type is encountered.public int getMaxObjectNumber()
public java.util.Vector getFields() throws InvalidPdfObjectException
InvalidPdfObjectException
private void getFieldsAddField(java.util.Vector fieldList, PjReference fieldRef) throws InvalidPdfObjectException
InvalidPdfObjectException
public void updateFieldValue(PjDictionary origField, PjDictionary field, java.lang.String value) throws PdfFormatException, InvalidPdfObjectException
private static void replaceTextData(java.util.Vector pmVector, PjString oldText, PjString newText)
private static void adjustTextMatrixX(java.util.Vector pmVector, float rectWidth)
private static void clearTextMatrixX(java.util.Vector pmVector)
private void inheritPageAttributesCollapse(PjName name, java.util.Hashtable ht, PjPagesNode newNode, PjPagesNode parent)
private void inheritFieldAttributesCollapse(PjName name, java.util.Hashtable ht, PjDictionary newNode, PjDictionary parent)
private void init()
private void createEmpty()
private void readFromFile(java.lang.String filename) throws java.io.IOException, PjException
java.io.IOException
PjException