|
Java Tool Kit | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectITT.WAFr.Utilities.PdfFile
The PdfFile class represents a stream in Adobe's Portable Document Format (PDF).
This class can be used to generate an output stream in PDF from any input stream representing a well-formed HTML document.
The input source of the PDF document can be a URL object, String representing the address of a Web page, or any valid InputStream object.
Do not use buffered streams, as the PdfFile class will buffer both the input and output streams automatically.
In addition, a base URL object, or String representing a base location, can be passed to enable relative links for resources within the source HTML. Local file system URLs (file:///) are permitted as well.
The Create() method will interpret and rendered the input HTML source within a virtual browser at an auto-adjusting or specified explicit width. See the BrowserWidth(double,int) method description for details. Upon rendering, the resulting PDF page will be scaled to fit within the default or specified document size, taking the default or set document margins into account.
The Create() method should be called last following all parameter setting methods. Once called, subsequent calls to the Create() method will throw an exception and calls to all other methods will be ignored. A valid OutputStream object, representing a destination file or any other sub class, must be passed. Again, this stream should not be buffered.
Upon success or failure, the output stream, and any applicable input stream, will be closed automatically.
| Nested Class Summary | |
class |
PdfFile.BrowserWidthException
This exception is thrown when the virtual browser render pixel width is not specified as a positive integer. |
class |
PdfFile.DocumentSizeException
This exception is thrown when the specified document width or height, upon subtracting margins, is less than zero (0) units. |
class |
PdfFile.MarginsException
This exception is thrown when the specified document margins are less than zero (0) units. |
class |
PdfFile.PageExhaustedException
This exception is thrown when the specified HTML input source has already been processed and resources have been released. |
class |
PdfFile.ParsingException
This exception is thrown when the specified HTML input source could not be successfully parsed. |
static interface |
PdfFile.PdfDocumentSize
The PdfDocumentSize interface contains the well-known standard document sizes. |
class |
PdfFile.TimeoutException
This exception is thrown when the specified HTML input source does not process in the timeout period allotted. |
class |
PdfFile.UrlException
This exception is thrown when a specified Internet address fails to convert to a valid URL. |
| Field Summary | |
static boolean |
AcrobatFonts
Field representing if the PDF document supports embedded Adobe Acrobat fonts only. |
static int |
Centimeters
Field representing measurement in units of centimeters. |
static int |
cm
Field representing measurement in units of cm or centimeters. |
static boolean |
CustomFonts
Field representing if the PDF document supports custom fonts local to the viewer. |
static int |
FitToPage
Field representing if the virtual browser render width should adjust to fit entire Web page width. |
static int |
in
Field representing measurement in units of in or inches. |
static int |
Inches
Field representing measurement in units of inches. |
static boolean |
Landscape
Field representing a page orientation of landscape. |
static int |
Millimeters
Field representing measurement in units of millimeters. |
static int |
mm
Field representing measurement in units of mm or millimeters. |
static int |
Pixels
Field representing measurement in units of pixels. |
static boolean |
Portrait
Field representing a page orientation of portrait. |
static int |
px
Field representing measurement in units of px or pixels. |
| Constructor Summary | |
PdfFile()
Constructs a new PdfFile object. |
|
| Method Summary | |
void |
BrowserWidth(double fWidth,
int iUnits)
Sets the virtual browser render width for the source HTML using the specified width and unit of measure. |
void |
BrowserWidth(int iWidth)
Sets the virtual browser render width for the source HTML to the specified number of pixels. |
void |
Create(InputStream oInput,
OutputStream oOutput)
Creates an output stream representing a PDF document for the HTML page passed as an input stream. |
void |
Create(InputStream oInput,
OutputStream oOutput,
String sUrl)
Creates an output stream representing a PDF document for the HTML page passed as an input stream with a base URL of the specified string. |
void |
Create(InputStream oInput,
OutputStream oOutput,
URL oUrl)
Creates an output stream representing a PDF document for the HTML page passed as an input stream with specified base URL. |
void |
Create(String sUrl,
OutputStream oOutput)
Creates an output stream representing a PDF document for the HTML page at the string specifying a URL location. |
void |
Create(URL oUrl,
OutputStream oOutput)
Creates an output stream representing a PDF document for the HTML page at the specifed URL. |
void |
DocumentMargins(double fTop,
double fLeft,
double fBottom,
double fRight,
int iUnits)
Sets the output PDF document margins to the parameters in a specified unit of measure. |
void |
DocumentMargins(Insets oInsets)
Sets the output PDF document margins to the pixel insets specified. |
void |
DocumentMargins(Insets oInsets,
int iUnits)
Sets the output PDF document margins to the insets specified in any unit of measure. |
void |
DocumentMargins(int iTop,
int iLeft,
int iBottom,
int iRight)
Sets the output PDF document margins to the pixel insets specified. |
void |
DocumentSize(Dimension oDimensions)
Sets the output PDF document size to the dimension in pixels. |
void |
DocumentSize(Dimension oDimensions,
int iUnits)
Sets the output PDF document size to the dimension specified in any unit of measure. |
void |
DocumentSize(double fWidth,
double fHeight,
int iUnits)
Sets the output PDF document size to the width and height in the specified unit of measure. |
void |
DocumentSize(int iWidth,
int iHeight)
Sets the output PDF document size to the specified width and height in pixels. |
void |
FontSupport(boolean bFontSupport)
Sets the indicator enabling the PDF to attempt use of all custom fonts used within the source HTML. |
void |
ImageSplitting(boolean bAllow)
Sets the parameter indicating if the PDF document will split images at page breaks. |
void |
PageOrientation(boolean bOrientation)
Sets the page orientation of the PDF document. |
void |
TextSplitting(boolean bAllow)
Sets the parameter indicating if the PDF document will divide text characters vertically at page breaks. |
void |
Timeout(int iSeconds)
Sets the timeout in seconds for the Create() method's input source HTML processing. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final boolean AcrobatFonts
public static final int Centimeters
centimeters.
public static final int cm
cm or centimeters.
public static final boolean CustomFonts
public static final int FitToPage
public static final int in
in or inches.
public static final int Inches
inches.
public static final boolean Landscape
landscape.
public static final int Millimeters
millimeters.
public static final int mm
mm or millimeters.
public static final int Pixels
pixels.
public static final boolean Portrait
portrait.
public static final int px
px or pixels.
| Constructor Detail |
public PdfFile()
PdfFile object.
| Method Detail |
public void BrowserWidth(double fWidth,
int iUnits)
The PdfFile class must first interpret the input source HTML as does any Web browser. And like other browsers, you can decide the width. In a Web browser you simply resize the physical window. This method will simulate sizing of a physical Web browser window.
The behavior is exactly that of any Web browser. If the render width entered is greater than the layout of the source HTML, white space on one or both sides will be visible. If the width is less than the width of the HTML input, the rendered PDF will be cropped, as if viewing in a Web browser window too narrow to accommodate a Web page.
Any decimal numeric value can be specified for the width in either Inches, Centimeters, Millimeters, or Pixels.
Use the field value of FitToPage to dynamically set the width of the virtual browser to the required width of the input HTML source. This setting ignores the unit of measure.
FitToPage is the default value.
fWidth - a double specifying the width in which the virtual browser will render.iUnits - a field value representing a unit of measure.BrowserWidth(int)public void BrowserWidth(int iWidth)
See the BrowserWidth(double,int) method for description.
iWidth - an integer specifying the number of pixels in which the virtual browser will render.BrowserWidth(double,int)
public void Create(InputStream oInput,
OutputStream oOutput)
throws IOException,
PdfFile.UrlException,
PdfFile.BrowserWidthException,
PdfFile.MarginsException,
PdfFile.DocumentSizeException,
PdfFile.ParsingException,
PdfFile.TimeoutException,
PdfFile.PageExhaustedException
This method does not support a base URL for relative linked resources. All resources must contain absolute paths to properly render.
The specified input and output stream should not be buffered as the PdfFile class handles buffering internally.
This method will close both the input and output streams regardless of success.
oInput - an input stream containing the HTML source to be converted.oOutput - the destination output stream.
IOException - if the output stream can not be written to.
PdfFile.UrlException - if the specified URL is not valid.
PdfFile.BrowserWidthException - if the virtual browser width is invalid.
PdfFile.MarginsException - if the document margins are invalid.
PdfFile.DocumentSizeException - if the document size is invalid.
PdfFile.ParsingException - if the HTML source fails to parse.
PdfFile.TimeoutException - if the HTML source fails to render in the specified timeout period.
PdfFile.PageExhaustedException - if the PDF document has already been rendered.
public void Create(InputStream oInput,
OutputStream oOutput,
String sUrl)
throws IOException,
PdfFile.UrlException,
PdfFile.BrowserWidthException,
PdfFile.MarginsException,
PdfFile.DocumentSizeException,
PdfFile.ParsingException,
PdfFile.TimeoutException,
PdfFile.PageExhaustedException
The specified input and output stream should not be buffered as the PdfFile class handles buffering internally.
This method will close both the input and output streams regardless of success.
oInput - an input stream containing the HTML source to be converted.oOutput - the destination output stream.sUrl - representing the the base URL to be used for relative linked resources.
IOException - if the output stream can not be written to.
PdfFile.UrlException - if the specified URL is not valid.
PdfFile.BrowserWidthException - if the virtual browser width is invalid.
PdfFile.MarginsException - if the document margins are invalid.
PdfFile.DocumentSizeException - if the document size is invalid.
PdfFile.ParsingException - if the HTML source fails to parse.
PdfFile.TimeoutException - if the HTML source fails to render in the specified timeout period.
PdfFile.PageExhaustedException - if the PDF document has already been rendered.
public void Create(InputStream oInput,
OutputStream oOutput,
URL oUrl)
throws IOException,
PdfFile.UrlException,
PdfFile.BrowserWidthException,
PdfFile.MarginsException,
PdfFile.DocumentSizeException,
PdfFile.ParsingException,
PdfFile.TimeoutException,
PdfFile.PageExhaustedException
The specified input and output stream should not be buffered as the PdfFile class handles buffering internally.
This method will close both the input and output streams regardless of success.
oInput - an input stream containing the HTML source to be converted.oOutput - the destination output stream.oUrl - a URL specifying the base URL to be used for relative linked resources.
IOException - if the output stream can not be written to.
PdfFile.UrlException - if the specified URL is not valid.
PdfFile.BrowserWidthException - if the virtual browser width is invalid.
PdfFile.MarginsException - if the document margins are invalid.
PdfFile.DocumentSizeException - if the document size is invalid.
PdfFile.ParsingException - if the HTML source fails to parse.
PdfFile.TimeoutException - if the HTML source fails to render in the specified timeout period.
PdfFile.PageExhaustedException - if the PDF document has already been rendered.
public void Create(String sUrl,
OutputStream oOutput)
throws IOException,
PdfFile.UrlException,
PdfFile.BrowserWidthException,
PdfFile.MarginsException,
PdfFile.DocumentSizeException,
PdfFile.ParsingException,
PdfFile.TimeoutException,
PdfFile.PageExhaustedException
The specified output stream should not be buffered as the PdfFile class handles buffering internally.
This method will close the output stream regardless of success.
sUrl - a string representing the URL of the HTML input source.oOutput - the destination output stream.
IOException - if the output stream can not be written to.
PdfFile.UrlException - if the specified URL is not valid.
PdfFile.BrowserWidthException - if the virtual browser width is invalid.
PdfFile.MarginsException - if the document margins are invalid.
PdfFile.DocumentSizeException - if the document size is invalid.
PdfFile.ParsingException - if the HTML source fails to parse.
PdfFile.TimeoutException - if the HTML source fails to render in the specified timeout period.
PdfFile.PageExhaustedException - if the PDF document has already been rendered.
public void Create(URL oUrl,
OutputStream oOutput)
throws IOException,
PdfFile.UrlException,
PdfFile.BrowserWidthException,
PdfFile.MarginsException,
PdfFile.DocumentSizeException,
PdfFile.ParsingException,
PdfFile.TimeoutException,
PdfFile.PageExhaustedException
The specified output stream should not be buffered as the PdfFile class handles buffering internally.
This method will close the output stream regardless of success.
oUrl - a URL specifying the HTML input source.oOutput - the destination output stream.
IOException - if the output stream can not be written to.
PdfFile.UrlException - if the specified URL is not valid.
PdfFile.BrowserWidthException - if the virtual browser width is invalid.
PdfFile.MarginsException - if the document margins are invalid.
PdfFile.DocumentSizeException - if the document size is invalid.
PdfFile.ParsingException - if the HTML source fails to parse.
PdfFile.TimeoutException - if the HTML source fails to render in the specified timeout period.
PdfFile.PageExhaustedException - if the PDF document has already been rendered.
public void DocumentMargins(double fTop,
double fLeft,
double fBottom,
double fRight,
int iUnits)
Any decimal numeric value can be specified for the individual margins in either Inches, Centimeters, Millimeters, or Pixels.
The default margins are:
Top: .50 inches
Left: .25 inches
Bottom: .25 inches
Right: .25 inches
fTop - a double representing the top margin of the output PDF.fLeft - a double representing the left margin of the output PDF.fBottom - a double representing the bottom margin of the output PDF.fRight - a double representing the right margin of the output PDF.iUnits - a field value representing a unit of measure.DocumentMargins(Insets),
DocumentMargins(int,int,int,int)public void DocumentMargins(Insets oInsets)
oInsets - an Insets object representing the top, left, bottom, and right margins of the output PDF in pixels.DocumentMargins(double,double,double,double,int),
DocumentMargins(int,int,int,int)
public void DocumentMargins(Insets oInsets,
int iUnits)
An Insets object representing the top, left, bottom, and right margins in either Inches, Centimeters, Millimeters, or Pixels can be specified as the document margins.
oInsets - an Insets object representing the top, left, bottom, and right margins of the output PDF.iUnits - a field value representing a unit of measure.DocumentMargins(double,double,double,double,int),
DocumentMargins(int,int,int,int)
public void DocumentMargins(int iTop,
int iLeft,
int iBottom,
int iRight)
iTop - an integer representing the top margin of the output PDF in pixels.iLeft - an integer representing the left margin of the output PDF in pixels.iBottom - an integer representing the bottom margin of the output PDF in pixels.iRight - an integer representing the right margin of the output PDF in pixels.DocumentMargins(double,double,double,double,int),
DocumentMargins(Insets)public void DocumentSize(Dimension oDimensions)
This method is most convenient for using the standard pre-defined field value document sizes from the PdfFile.PdfDocumentSize interface, although any pixel dimension can be specified.
The default value is the field PdfFile.PdfDocumentSize.Letter, which is 8.5 x 11 inches.
oDimensions - a Dimension object representing the pixel width and height of the output PDF.
public void DocumentSize(Dimension oDimensions,
int iUnits)
A Dimension object representing the width and height in either Inches, Centimeters, Millimeters, or Pixels can be specified as the document size.
oDimensions - a Dimension object representing the width and height of the output PDF.iUnits - a field value representing a unit of measure.DocumentSize(Dimension)
public void DocumentSize(double fWidth,
double fHeight,
int iUnits)
Any decimal numeric value can be specified for the width and height in either Inches, Centimeters, Millimeters, or Pixels.
fWidth - a double representing the width of the output PDF.fHeight - a double representing the height of the output PDF.iUnits - a field value representing a unit of measure.DocumentSize(Dimension)
public void DocumentSize(int iWidth,
int iHeight)
iWidth - an integer representing the pixel width of the output PDF.iHeight - an integer representing the pixel height of the output PDF.DocumentSize(Dimension)public void FontSupport(boolean bFontSupport)
NOTE: If this parameter is set to the field value of CustomFonts, Adobe Acrobat Reader will popup an informational dialog box specifying that any custom font being used does not contain a valid BBox. This is because the PdfFile class cannot generate dynamic font descriptors for fonts within the HTML source document. It is recommended that this method not be used.
To prevent this dialog, use the field value AcrobatFonts which substitutes all fonts to one of the 14 embedded Adobe Acrobat fonts.
The field value AcrobatFonts is the default setting.
bFontSupport - AcrobatFonts for embedded fonts only, CustomFonts for any utilized fonts.public void ImageSplitting(boolean bAllow)
A setting of true will allow images to be split and span pages.
If the image is greater in height than the page height, the image will split regardless of this setting.
This setting is the true by default.
bAllow - true to enable, false to prohibit image splitting.public void PageOrientation(boolean bOrientation)
This setting is the field value of Portrait by default.
bOrientation - a field value of Portrait or Landscape.public void TextSplitting(boolean bAllow)
A setting of true will allow text characters to be split and span pages.
This setting is the false by default.
bAllow - true to enable, false to prohibit text splitting.public void Timeout(int iSeconds)
Create() method's input source HTML processing.
A setting of zero (0) or less will result in no timeout, or process until completion.
The default is 60 seconds.
iSeconds - an integer specifying the timeout in seconds.
|
Java Tool Kit | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||