|
Gnostice PDFOne Java
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.gnostice.pdfone.PdfDocument
public class PdfDocument
This class is used to create, read from, and write to PDF
documents. To create a new PDF file
and then write to it, a PdfDocument object should be
created with a PdfWriter object. (Henceforth, this
will be known as "creation mode.") To
read from an existing PDF file,
and possibly make changes and save it to a new file, a
PdfDocument object should be created with a
PdfReader object. (This will be referred as "reading
mode" in the rest of this documentation.)
The PdfDocument class offers numerous methods to
work with elements such as text, images, shapes, tables, form
fields, annotations, bookmarks, and pages in PDF documents.
When content is written to a new PdfDocument object,
a default PdfPage object is automatically created
and added to the PdfDocument. This
PdfPage also becomes PdfDocument's
"current page." Whenever data is written to a document without
explicitly specifying a page range, the data is automatically
written to the PdfDocument's current page. This
does not change even when new PdfPage objects have
been added to the PdfDocument object. To make a page
that is to be added set as the current page, the overloaded
add(PdfPage p, boolean setAsCurrentPage) method should be
used. To write content to a specific page that is not necessarily
the current page, methods that have a page range argument should be
used.
While writing to a PdfDocument object, the position
where the content should appear is very important. The coordinates
of the position is always made in reference to the top-left corner
the PdfDocument's current page. Whenever
coordinates, position, or sizes are used, they are usually applied
in terms of the document's current measurement unit, which can be
pixels, twips, points, inches, or centimeters. However, in
situations where a measurement unit cannot be applied or
determined, the measurement unit will be by default points.
Every document has a default pen setting and a default brush setting. The pen for example is used to stroke the borders when a rectangle is drawn. In the same example, the brush would be used when the area bounded by the rectangle is filled.
PdfWriter,
PdfReader,
PdfPage| Field Summary | |
|---|---|
static int |
ALIGNMENT_CENTER
|
static int |
ALIGNMENT_LEFT
|
static int |
ALIGNMENT_RIGHT
|
boolean |
autoPaginate
Document property determining whether a new page will be automatically appended when content written to current page starts overflowing the page's confines. |
static int |
MERGE_INCLUDE_ALL
Flag for inclusion of annotations, bookmarks, document-level actions, page-level actions, and form fields when merging documents. |
static int |
MERGE_INCLUDE_ANNOTATIONS
Flag for inclusion of annotations when merging documents. |
static int |
MERGE_INCLUDE_BOOKMARKS
Flag for inclusion of bookmarks when merging documents. |
static int |
MERGE_INCLUDE_DOCUMENT_ACTIONS
Flag for inclusion of document-level actions when merging documents. |
static int |
MERGE_INCLUDE_FORMFIELDS
Flag for inclusion of form fields when merging documents. |
static int |
MERGE_INCLUDE_PAGE_ACTIONS
Flag for inclusion of page-level actions when merging documents. |
static String |
VERSION_1_4
PDF version 1.4 |
static String |
VERSION_1_5
PDF version 1.5 |
static String |
VERSION_1_6
PDF version 1.6 |
| Constructor Summary | |
|---|---|
PdfDocument(PdfReader r)
Constructs a new PdfDocument with a
PdfReader object. |
|
PdfDocument(PdfWriter w)
Constructs a new PdfDocument object with a
PdfWriter object. |
|
| Method Summary | |
|---|---|
void |
add(PdfPage p)
Adds specified PdfPage to this
PdfDocument. |
void |
add(PdfPage p,
boolean setAsCurrentPage)
Adds specified PdfPage to this
PdfDocument and, if
setAsCurrentPage is true, sets the
PdfPage as the PdfDocument's
current page. |
void |
addAction(int namedAction)
Adds a named action that needs to be executed by viewer applications when they display the document. |
void |
addAction(int actionType,
int pageNum)
Adds a go-to action to the document. |
void |
addAction(int event,
int actionType,
String javascript)
Adds a Javascript action to specified document-level event. |
void |
addAction(int actionType,
String javascriptOrURI)
Sets this document to execute action specified by javascriptOrURI when the document is displayed. |
void |
addAction(int actionType,
String applicationToLaunch,
boolean isPrint,
String parameterToApplication)
Add a document-level action for launching a specified application with specified parameters or open/print specified document. |
void |
addAnnotation(PdfAnnot annotation,
int pageNo)
Adds specified annotation to specified page. |
void |
addAnnotationList(List annotList,
int pageNo)
Adds a specified list of annotations to a specified page. |
void |
addAnnotationList(List annotList,
int pageNo,
boolean removeExistingAnnots)
Adds a specified list of annotations to a specified page, and removes or keeps existing annotations. |
void |
addAnnotationList(List annotList,
String[] pageRanges,
boolean removeExistingAnnots,
int measurementUnit)
Adds specified list of annotations to specified pages at locations in specified units, and also remove or keep existing annotations in the document. |
void |
addAnnotationList(List annotList,
String[] pageRanges,
int measurementUnit)
Adds specified list of annotations to specified pages at locations in specified units. |
PdfBookmark |
addBookmark(int namedAction,
String title,
PdfBookmark parent)
Returns a new child bookmark (added under parent)
with specified title, and sets the bookmark to perform
specified named action. |
PdfBookmark |
addBookmark(String title,
PdfBookmark parent,
int pageNo)
Returns a new child bookmark (added under parent)
with specified title, and sets the bookmark to lead to
specified page. |
PdfBookmark |
addBookmark(String title,
PdfBookmark parent,
int pageNo,
double left,
double top,
double zoom)
Returns a new child bookmark (added under parent)
with specified title, and sets the bookmark to lead to
specified location on specified page with specified zoom. |
PdfBookmark |
addBookmark(String title,
PdfBookmark parent,
int pageNo,
double x,
double y,
double width,
double height)
Returns a new child bookmark (added under parent),
and sets the bookmark's
destination
to a rectangular area with specified top-left
corner (x, y), width and
height. |
PdfBookmark |
addBookmark(String title,
PdfBookmark parent,
int pageNo,
double pos,
int fit)
Returns a new child bookmark (added under parent),
and sets the bookmark's destination specified by
pageNo, pos and fit. |
PdfBookmark |
addBookmark(String title,
PdfBookmark parent,
int pageNo,
int fit)
Returns a new child bookmark (added under parent)
with specified title, and sets the bookmark's destination
specified by pageNo and fit. |
PdfBookmark |
addBookmark(String title,
PdfBookmark parent,
int pageNo,
PdfRect rect)
Returns a new child bookmark (added under parent)
with specified title and sets the bookmark to lead to
specified rectanglular area on specified page. |
PdfBookmark |
addBookmark(String title,
PdfBookmark parent,
int pageNo,
Rectangle rect)
Returns a new child bookmark (added under parent)
with specified title, and sets the bookmark to lead to
specified rectangular area on specified page. |
PdfBookmark |
addBookmark(String title,
PdfBookmark parent,
String applicationToLaunch,
boolean print)
Adds a new child bookmark (under parent), and
sets it to launch a specified application or print a specified
file. |
PdfBookmark |
addBookmark(String title,
PdfBookmark parent,
String javascriptOrURI,
int actionType)
Adds a new child bookmark (under parent) and
sets it execute a Javascript script or resolve a URI (Uniform
Resource Identifier). |
PdfBookmark |
addBookmark(String title,
PdfBookmark parent,
String pdfFileName,
int pageNo,
boolean newWindow)
Returns a new child bookmark (added under parent),
and sets it to open a specified page on a specified PDF
document in the same window or a new window of the viewer. |
void |
addDefaultFormFont(PdfFont font)
|
void |
addDefaultFormFontList(List fontList)
|
void |
addFooterImage(PdfImage img,
int position,
boolean underlay,
String pageRange)
Adds PdfImage object to footer of pages in
specified page range. |
void |
addFooterImage(String path,
int position,
boolean underlay,
String pageRange)
Adds image, specified by its pathname, to footer of pages in specified page range. |
void |
addFooterText(String text,
PdfFont font,
int position,
boolean underlay,
String pageRange)
Adds specified text to footer of pages in specified page range. |
void |
addFooterText(String text,
PdfFont font,
PdfRect rect,
int alignment,
int firstLinePosition,
int position,
boolean underlay,
String pageRange)
Adds a text footer to a specfied page range with specified font, first-line position, vertical/horizontal alignment, and underlay settings. |
void |
addFormField(PdfFormField formField,
int pageNo)
Add specified form field to specified page. |
void |
addFormField(PdfFormField f,
String[] pageRanges)
Adds children of specified form field (radio button group or check box group) to a specified page ranges. |
void |
addFormFieldList(List formFieldList,
int pageNo)
Add a list of form field to a specified page. |
void |
addHeaderImage(PdfImage img,
int position,
boolean underlay,
String pageRange)
Adds a PdfImage object to header of pages in
specified page range. |
void |
addHeaderImage(String path,
int position,
boolean underlay,
String pageRange)
Adds image, specified by its pathname, to footer of pages in specified page range. |
void |
addHeaderText(String text,
PdfFont font,
int position,
boolean underlay,
String pageRange)
Adds specified text to header of pages in specified page range. |
void |
addHeaderText(String text,
PdfFont font,
PdfRect rect,
int alignment,
int firstLinePosition,
int position,
boolean underlay,
String pageRange)
Adds specified text as a header on a specified rectangular area in specified pages with specified font, alignment, first-line position, vertical/horizontal position, and underlay settings. |
void |
addTable(PdfTable table,
double x,
double y,
int pageNo)
Renders a specified table at a specfied location on specified page. |
void |
addTable(PdfTable table,
double x,
double y,
int pageNo,
PdfFont f)
Renders a specified table at a specfied location on specified page with specified font. |
void |
addThumbnailImage(String path,
int pageNo)
Adds specified image as thumbnail for specified page. |
void |
addToFiltersList(int filter)
Adds a filter to the list of filters used to encode stream objects in this document. |
void |
addWatermarkImage(PdfImage image,
int position,
boolean applyPageMargins,
double angle,
boolean underlay,
String pageRange)
Adds PdfImage object as watermark with its exact
position determined by position and
applyPageMargins. |
void |
addWatermarkImage(PdfImage image,
int position,
double angle,
boolean underlay,
String pageRange)
Adds PdfImage object as watermark on pages in
specified page range. |
void |
addWatermarkImage(String path,
int position,
boolean applyPageMargins,
double angle,
boolean underlay,
String pageRange)
Adds image, specified by its pathname, as watermark with its exact position determined by position and
applyPageMargins on pages in specified page
range. |
void |
addWatermarkImage(String path,
int position,
double angle,
boolean underlay,
String pageRange)
Adds image, specified by its pathname, as watermark on pages in specified page range. |
void |
addWatermarkText(String text,
PdfFont font,
int position,
boolean applyPageMargins,
double angle,
boolean underlay,
String pageRange)
Adds specified text as watermark with its exact position determined by position and
applyPageMargins on pages in specified page
range. |
void |
addWatermarkText(String text,
PdfFont font,
int position,
double angle,
boolean underlay,
String pageRange)
Adds specified text as watermark on pages in specified page range. |
void |
addWatermarkText(String text,
PdfFont font,
PdfRect rect,
int alignment,
int firstLinePosition,
int position,
double angle,
boolean underlay,
String pageRange)
Adds specified text as a watermark to a specified rectangular area on a specified pages with specified font, alignment, first-line position, position, rotation, and underlay settings. |
void |
appendPagesFrom(PdfDocument d,
String pageRange)
Extracts specified pages from a specified document and then appends them to this document. |
void |
appendPagesFrom(String path,
String pageRange)
Extracts specified pages from a document (specified by its pathname) and then appends them to this document. |
void |
attachDocument(String fileName)
Adds specified file as an attachment to the document. |
void |
deleteFormFields()
Removes all form fields in the document. |
void |
deleteFormFields(int type)
Removes all form fields of specified type in the document. |
void |
deleteFormFields(String name)
Removes all form fields with specified name in the document. |
void |
deleteFormFieldsOnPage(int pageNo)
Removes all form fields on specified page. |
void |
deleteFormFieldsOnPage(int pageNo,
int type)
Removes all form fields of specified type on specified page. |
void |
deleteFormFieldsOnPage(int pageNo,
String name)
Removes all form fields with specified name in specified page. |
void |
deletePages(String pageRange)
Deletes pages in specified page range from this PdfDocument. |
void |
disableAllMargins(String pageRange)
Disables all margins on pages in specified page range. |
void |
drawArc(PdfRect rect,
double startAngle,
double arcAngle)
Draws an arc on the current page of this PdfDocument. |
void |
drawArc(PdfRect rect,
double startAngle,
double arcAngle,
String pageRange)
Draws an arc on pages in specified page range. |
void |
drawBezierCurve(double startX,
double startY,
double ctrlX,
double ctrlY,
double endX,
double endY,
boolean isFill,
boolean isStroke)
Draws a Bézier curve with a single control point on current page of this PdfDocument. |
void |
drawBezierCurve(double startX,
double startY,
double ctrlX,
double ctrlY,
double endX,
double endY,
boolean isFill,
boolean isStroke,
String pageRange)
Draws a Bézier curve with a single control point on pages in specified page range in this PdfDocument. |
void |
drawBezierCurve(double startX,
double startY,
double ctrlX1,
double ctrlY1,
double ctrlX2,
double ctrlY2,
double endX,
double endY,
boolean isFill,
boolean isStroke)
Draws a Bézier curve with two control points on current page of this PdfDocument. |
void |
drawBezierCurve(double startX,
double startY,
double ctrlX1,
double ctrlY1,
double ctrlX2,
double ctrlY2,
double endX,
double endY,
boolean isFill,
boolean isStroke,
String pageRange)
Draws a Bézier curve with two control points on pages in specified page range on this PdfDocument. |
void |
drawCircle(double x,
double y,
double radius,
boolean isFill,
boolean isStroke)
Draws a circle with specified radius on this PdfDocument's current page. |
void |
drawCircle(double x,
double y,
double radius,
boolean isFill,
boolean isStroke,
String pageRange)
Draws a circle with specified radius on pages in specified page range on this PdfDocument. |
void |
drawEllipse(double x1,
double y1,
double x2,
double y2,
boolean isFill,
boolean isStroke)
Draws an ellipse on this PdfDocument's current
page. |
void |
drawEllipse(double x1,
double y1,
double x2,
double y2,
boolean isFill,
boolean isStroke,
String pageRange)
Draws an ellipse on pages in specified page range on this PdfDocument's current page. |
void |
drawImage(PdfImage img,
double x,
double y)
Draws specified image at position ( x, y)
on this PdfDocument's current page. |
void |
drawImage(PdfImage img,
double x,
double y,
double rotation)
Draws specified image rotated by rotation
degrees at position (x, y) on this
PdfDocument's current page. |
void |
drawImage(PdfImage img,
double x,
double y,
double width,
double height)
Draws specified image at position ( x, y) with specified height and
width on this PdfDocument's current page. |
void |
drawImage(PdfImage img,
double x,
double y,
double width,
double height,
double rotation)
Draws specified image rotated by rotation degrees
at position (x, y) with specified
height and width on this PdfDocument's current
page. |
void |
drawImage(PdfImage img,
double x,
double y,
double width,
double height,
double rotation,
String pageRange)
Draws specified image rotated by rotation degrees
at position (x, y) with specified
height and width on pages in specified page range. |
void |
drawImage(PdfImage img,
double x,
double y,
double width,
double height,
String pageRange)
Draws specified image at position ( x, y) with specified height and
width on pages in specified page range. |
void |
drawImage(PdfImage img,
double x,
double y,
double rotation,
String pageRange)
Draws specified image rotated by rotation degrees
at position (x, y) on pages in
specified page range. |
void |
drawImage(PdfImage img,
double x,
double y,
String pageRange)
Draws specified image at position ( x, y) on pages in specified page
range. |
void |
drawImage(PdfImage img,
PdfPoint pt)
Draws specified image at specified point on this PdfDocument's current page. |
void |
drawImage(PdfImage img,
PdfPoint pt,
double rotation)
Draws specified image rotated by rotation degrees
at specified point on this PdfDocument's current
page. |
void |
drawImage(PdfImage img,
PdfPoint pt,
double width,
double height)
Draws specified image at specified point with specified width and height on this PdfDocument's current page. |
void |
drawImage(PdfImage img,
PdfPoint pt,
double width,
double height,
double rotation)
Draws specified image rotated by rotation
degrees at specified point on this PdfDocument's
current page. |
void |
drawImage(PdfImage img,
PdfPoint pt,
double width,
double height,
double rotation,
String pageRange)
Draws specified image rotated by rotation degrees
at specified point with specified width and height on pages in
the specified page range. |
void |
drawImage(PdfImage img,
PdfPoint pt,
double width,
double height,
String pageRange)
Draws specified image at specified point with specified width and height on pages in the specified page range. |
void |
drawImage(PdfImage img,
PdfPoint pt,
double rotation,
String pageRange)
Draws specified image rotated by rotation degrees
at specified point on pages in the specified page range. |
void |
drawImage(PdfImage img,
PdfPoint pt,
String pageRange)
Draws specified image at specified point on pages in specified page range. |
void |
drawImage(PdfImage img,
PdfRect rect)
Draws specified image inside specified rectangle on this PdfDocument's current page. |
void |
drawImage(PdfImage img,
PdfRect rect,
double rotation)
Draws specified image rotated by rotation degrees
inside specified rectangle on this PdfDocument's
current page. |
void |
drawImage(PdfImage img,
PdfRect rect,
double rotation,
String pageRange)
Draws specified image rotated by rotation degrees
inside specified rectangle on pages in specified range. |
void |
drawImage(PdfImage img,
PdfRect rect,
String pageRange)
Draws specified image inside specified rectangle on pages in specified page range. |
void |
drawImage(String path,
double x,
double y)
Draws image specified by its pathname at position ( x, y) on this
PdfDocument's current page. |
void |
drawImage(String path,
double x,
double y,
double rotation)
Draws image specified by its pathname rotated at rotation degrees at position
(x, y) on this
PdfDocument's current page. |
void |
drawImage(String path,
double x,
double y,
double width,
double height)
Draws image specified by its pathname at position (x, y) with specified width and height on this PdfDocument's current page. |
void |
drawImage(String path,
double x,
double y,
double width,
double height,
double rotation)
Draws image specified by its pathname rotated by rotation degrees at position
(x, y) with specified width and
height on this PdfDocument's current page. |
void |
drawImage(String path,
double x,
double y,
double width,
double height,
double rotation,
String pageRange)
Draws image specified by its pathname rotated by rotation degrees at position
(x, y) with specified width and
height on pages in specified page range. |
void |
drawImage(String path,
double x,
double y,
double width,
double height,
String pageRange)
Draws image specified by its pathname at position ( x, y)with specified width and
height on pages in specified page range. |
void |
drawImage(String path,
double x,
double y,
double rotation,
String pageRange)
Draws image specified by its pathname rotated by rotation degrees at position (x,
y)on pages in specified range. |
void |
drawImage(String path,
double x,
double y,
String pageRange)
Draws image specified by its pathname at position ( x, y) on pages in specified page
range. |
void |
drawImage(String path,
PdfPoint pt)
Draws image specified by its pathname at specified point on this PdfDocument's current page. |
void |
drawImage(String path,
PdfPoint pt,
double rotation)
Draws image specified by its pathname rotated by rotation degrees at specified point on this
PdfDocument's current page. |
void |
drawImage(String path,
PdfPoint pt,
double width,
double height)
Draws image specified by its pathname at specified point with specified width and height on this PdfDocument's
current page. |
void |
drawImage(String path,
PdfPoint pt,
double width,
double height,
double rotation)
Draws image specified by its pathname rotated by rotation degrees at specified point with
specified width and height on this PdfDocument's
current page. |
void |
drawImage( |