|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.secondmove.webpdfreports.HTML2PDFConvertor
HTMP2PDFConvertor is the class that allows you to create PDf documents either from a given URL or from an HTML string and a baseURL. The class greatly simplifies constructing PDF documents from HTML documents. The following codesnippet produces a multi-page PDF Document and opens the resulting document using the systems preferred PDF application. Simply pass the URL's of the pages to be contained in the document as argument to the tool.
public static void main (String args[]) {
if (args.length > 0) {
HTMP2PDFConvertor pdfConvertor = new HTMP2PDFConvertor();
pdfConvertor.createDocument("A4", PortraitOrientation);
for (int i = 0; i < args.length; i++) {
System.out.println("Processing " + args[i]);
pdfConvertor.appendPageWithURL(args[i]);
}
String name = pdfConvertor.closeDocument();
Runtime rt = java.lang.Runtime.getRuntime();
try {
rt.exec("open file:///" + name);
} catch (java.lang.Throwable t) {
System.out.println("Error opening file:" + t);
}
}
}
| Field Summary | |
static int |
AutoPagination
Documentation forthcoming |
static int |
ClipPagination
Documentation forthcoming |
static int |
FitPagination
Documentation forthcoming |
static int |
LandscapeOrientation
Orientation is landscape (page is wider than it is tall). |
static int |
PortraitOrientation
Orientation is portrait (page is taller than it is wide). |
| Constructor Summary | |
HTML2PDFConvertor()
|
|
| Method Summary | |
void |
appendPageWithHTMLStringAndBaseURL(java.lang.String htmlString,
java.lang.String baseURL)
Appends a page to the PDF document converting HTML to pdf |
void |
appendPageWithURL(java.lang.String url)
Appends a page to the PDF document converting HTML to pdf |
float |
bottomMargin()
Returns the bottom margin in points. |
java.lang.String |
closeDocument()
Closes the PDF document |
void |
createDocument()
Creates a PDF document using "A4" as the papername and PortraitOrientation as the orientation. |
void |
createDocument(PaperSize size,
int orientation)
Creates a PDF document. |
void |
createDocument(java.lang.String paperName,
int orientation)
Creates a pdf document. |
int |
horizontalPagination()
Returns the horizontal pagination mode. |
float |
leftMargin()
Returns the left margin in points. |
int |
orientation()
Returns the orientation of the document. |
java.lang.String |
paperName()
Returns the papername currently in use by this document. |
PaperSize |
paperSize()
Returns the papersize in points. |
float |
printScalingFactor()
Returns the scale factor percentage. |
boolean |
printsHorizontallyCentered()
Retrieves the horizontal centration mode. |
boolean |
printsVerticallyCentered()
Retrieves the vertical centration mode. |
float |
rightMargin()
Returns the right margin in points. |
void |
setBottomMargin(float margin)
Sets the bottom margin. |
void |
setHorizontalPagination(int paginationMode)
Sets the horizontal pagination mode. |
void |
setLeftMargin(float margin)
Sets the left margin. |
void |
setOrientation(int orientation)
Sets the orientation for the document. |
void |
setPaperName(java.lang.String name)
Sets the papername for this document Invocation only affects pages yet to be appended, not the pages already appended. |
void |
setPaperSize(PaperSize size)
Sets the papersize for the document. |
void |
setPrintScalingFactor(float factor)
Sets the scale factor percentage before pagination. |
void |
setPrintsHorizontallyCentered(boolean centered)
Sets the horizontal centration. |
void |
setPrintsVerticallyCentered(boolean centered)
Sets the vertical centration. |
void |
setRightMargin(float margin)
Sets the right margin. |
void |
setShouldPrintBackgrounds(boolean printBackgrounds)
Determines wether or not to print backgrounds |
void |
setTopMargin(float margin)
Sets the top margin. |
void |
setVerticalPagination(int paginationMode)
Sets the vertical pagination mode. |
boolean |
shouldPrintBackgrounds()
Returns wether or not backgrounds are printed, true if backgrounds are printed, false otherwise. |
float |
topMargin()
Returns the top margin in points. |
int |
verticalPagination()
Returns the vertical pagination mode. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int PortraitOrientation
orientation(),
setOrientation(int),
createDocument(),
createDocument(String, int),
Constant Field Valuespublic static final int LandscapeOrientation
orientation(),
setOrientation(int),
createDocument(),
createDocument(String, int),
Constant Field Valuespublic static final int AutoPagination
public static final int FitPagination
public static final int ClipPagination
| Constructor Detail |
public HTML2PDFConvertor()
| Method Detail |
public void createDocument()
createDocument(String, int),
createDocument(PaperSize, int),
PortraitOrientation,
LandscapeOrientation
public void createDocument(java.lang.String paperName,
int orientation)
paperName - Name of the papertype used for the document, e.g. "A4", "US Legal", "US Letter" etc.orientation - Determines the orientation of the document, either PortraitOrientation
or LandscapeOrientation.createDocument(),
PortraitOrientation,
LandscapeOrientation
public void createDocument(PaperSize size,
int orientation)
size - The PaperSize in pointsorientation - The orientation, either LandscapeOrientation or PortraitOrientationPaperSize.PaperSize(float, float),
PortraitOrientation,
LandscapeOrientationpublic java.lang.String closeDocument()
public void setPrintsHorizontallyCentered(boolean centered)
centered - If true, pages are centered horizontallyprintsHorizontallyCentered(),
setPrintsVerticallyCentered(boolean),
printsVerticallyCentered()public boolean printsHorizontallyCentered()
setPrintsHorizontallyCentered(boolean),
setPrintsVerticallyCentered(boolean),
printsVerticallyCentered()public void setPrintsVerticallyCentered(boolean centered)
centered - If true, pages are centered verticallysetPrintsHorizontallyCentered(boolean),
printsHorizontallyCentered(),
printsVerticallyCentered()public boolean printsVerticallyCentered()
setPrintsHorizontallyCentered(boolean),
printsHorizontallyCentered(),
setPrintsVerticallyCentered(boolean)public void setHorizontalPagination(int paginationMode)
horizontalPagination(),
AutoPagination,
ClipPagination,
FitPaginationpublic int horizontalPagination()
setHorizontalPagination(int),
AutoPagination,
ClipPagination,
FitPaginationpublic void setVerticalPagination(int paginationMode)
verticalPagination(),
AutoPagination,
ClipPagination,
FitPaginationpublic int verticalPagination()
setVerticalPagination(int),
AutoPagination,
ClipPagination,
FitPaginationpublic void setPrintScalingFactor(float factor)
factor - The scale factor percentageprintScalingFactor()public float printScalingFactor()
public void setOrientation(int orientation)
orientation - The orientaion for the document, either PortraitOrientation (taller than wide) or LandscapeOrientation (wider than tall).orientation(),
PortraitOrientation,
LandscapeOrientationpublic int orientation()
setOrientation(int),
PortraitOrientation,
LandscapeOrientationpublic void setPaperSize(PaperSize size)
size - The papersize in points.PaperSize.PaperSize(float, float)public PaperSize paperSize()
PaperSize.PaperSize(float, float)public void setPaperName(java.lang.String name)
name - The papername to be used, e.g. "A4".public java.lang.String paperName()
setPaperName(String)public void setLeftMargin(float margin)
margin - The left margin in points.public float leftMargin()
public void setRightMargin(float margin)
margin - The right margin in points.public float rightMargin()
public void setTopMargin(float margin)
margin - The top margin in points.public float topMargin()
public void setBottomMargin(float margin)
margin - The bottom margin in points.public float bottomMargin()
public void setShouldPrintBackgrounds(boolean printBackgrounds)
printBackgrounds - Enables or disables printing of background elements..public boolean shouldPrintBackgrounds()
public void appendPageWithHTMLStringAndBaseURL(java.lang.String htmlString,
java.lang.String baseURL)
htmlString - String containing the actual HTML contents.baseURL - The baseURL for the document.public void appendPageWithURL(java.lang.String url)
url - Any valid URL pointing to a document eg "http://www.apple.com" or "file:///Developer/Documentation/WebObjects/webobjects.html".appendPageWithHTMLStringAndBaseURL(String, String)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||