- Pure
Java PDF Generation engine - allows fast and easy PDF
creation from various sources and also convert even very complex
HTML/XHTML documents with single line of code - 100% in
house development - it does not depend on external packages.
- It converts and generates quickly and easily
PDF and PDF/A files directly from HTML, Plain Text, Microsoft
Word Docx, Rich Text Format RTF, JPEG, GIF, PNG, BMP
- Royalty free redistribution with your applications
- Automatic multiple
page layout, rendering and inclusion of all images, inline and
linked styles etc.
- Possibility
to specify
the desired Page format and margins and whether to scale
the content to fit inside or not
- Works
with any JRE/ JDK 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 9, 10, 11, 12,
13, 14, 15, 16 or higher
- Support
for
Oracle Forms and full generation of
PDF from Oracle Forms and CLOB
- Fully
compatible with Swing, SWT/Eclipse, Oracle Forms, Java
Servlets, JSP
- Support for all western
Latin languages such as English, German, French, Italian,
Spanish, Portuguese, Swedish, Norwegian etc.
- Support for
Arabic,
Cyrillic, Greek, Hebrew, Farsi, Hindi, Tamil and many other languages through
UTF-8 pdfGenerator.setCharset("utf-8")
character set
encoding and Chinese language
is also supported through the code:
pdfGenerator.setCharset("ISO-10646-UCS-2")
- Automatic embedding of
all TTF fonts contained inside the document when the UTF-8
encoding is set using the code:
pdfGenerator.setCharset("utf-8")
- Support for PDF/A file specification when pdfGenerator.setCharset("utf-8")
is set.
- Compatible with
Headless mode for server systems
- Compact size and fast document generation
- Possibility to specify
whether to split the pages automatically or to generate a
poster-like one page PDF file with automatically determining the
page length to fit the content.
- You can specify
Headers, Footers and Page numbers in any formatting and position
through full HTML formatting support.
- Now all hyperlinks
inside the HTML document are generated as links (annotations)
automatically into the resulting PDF file
- Support for
disabling the table breaking across multiple pages
- Support for
disabling lists breaking across multiple pages
- Support for the
CSS page break elements page-break-before:always,
page-break-after:always, page-break-inside:never
The use of the
PDFGenerator component is quite simple - with only a few
lines of code is possible to generate and convert practically
any document to PDF and add headers, footers, page numbers
etc.
If your document contains special fonts, characters or
symbols you should set the characters set to UTF-8 using the
following method -
pdfGenerator.setCharset("utf-8");
- this will also generate
PDF/A compliant file. Here are some
examples:
This method will recognize automatically if document is
html, docx, rtf, txt or image and will convert it accordingly. To use this
automatic conversion the URL must end with the corresponding extension like
docx, txt, rtf, jpeg, gif, png etc. Otherwise you can use the methods below
for specific cases.
import sferyx.administration.pdfgenerator.*;
PDFGenerator pdfGenerator=new PDFGenerator();
pdfGenerator.setMarginsForStandardPageFormat (10,10,10,10);
pdfGenerator.setCharset ("utf-8");
Will embed all fonts and generate PDF/A compliant file and will add support for non-latin languages.
pdfGenerator.generatePDFFromURL ("http://your_url_here", "c:/pdfgenerator-test1.pdf", "A4", "Portrait");
You can generate even very complex
PDF documents dynamically in your Java application by simply providing all the formatting
in HTML and inserting page breaks when new pages are needed - the PDFGenerator will take care automatically for all the pagination
of long
formatted text spanning through multiple pages and also tables, lists etc.
This functionality is perfect for creating various reports and other
documents which need to be generated dynamically with rich text formatting.
You can change the Page Headers and Footers when you want directly in the
multipage flow and the PDFGenerator takes care about the pagination
automatically so you don't have to worry how many pages span and how long
are the different document sections
import sferyx.administration.pdfgenerator.*;
PDFGenerator pdfGenerator=new
PDFGenerator();
//Create Header if needed - you can create also first page header if you
want
pdfGenerator.setHeader("<p
style=\"text-align:right;background-color:#ddd;\"><span
style=\"font-size:18pt;color:green;\"><b>This is the header
here</b></span></p>");
//Create Footer and Page Numbers - the page numbers can be inserted anywhere
in the document.
pdfGenerator.setFooter("<i>This
is some footer with page numbers Page: <b>@#SferyxPDFGenerator-PageNumber#@</b>
of pages: <b>@#SferyxPDFGenerator-TotalPagesNumber#@</b></i>");
//Open the content buffer to insert the content - HTML, Docx, RTF,
Text etc - everything can be merged together.
pdfGenerator.openContentBuffer();
//Append the content to the content buffer - you can insert styles,
images and any kind of formatting.
pdfGenerator.appendHTMLContentToContentBuffer("<style>body{font-size:12pt;color:blue;}
h1{background-color:yellow;}</style>");
pdfGenerator.appendHTMLContentToContentBuffer("<h1>This
is H1 header</h1>Some other text <b>very important <i>stuff</i></b> with
page break after");
//Insert page break to create new page - the PDFGenerator will handle
automatically all the pagination for long text if more pages are needed,
tables and everything.
pdfGenerator.addPageBreakToContentBuffer();
//Append the content for the new page.
pdfGenerator.appendHTMLContentToContentBuffer("<h2
style=\"background-color:green;border-bottom:1px solid red;color:white\">This
is second H2 header</h2>Some other text <span style=\"color:orange\">extremely
interesting <u>stuff</u></b></span><br>");
//Append Plain
Text Content
pdfGenerator.appendPlainTextContentToContentBuffer("Here
we put some plain text\nin new line other text\n\ttab space other stuff
here... with page break after");
//Insert another page break...
pdfGenerator.addPageBreakToContentBuffer();
pdfGenerator.appendHTMLContentToContentBuffer("<style>table{border-collapse:collapse;}
td{border:1px solid red;}</style>");
//Create table dynamically...
pdfGenerator.appendHTMLContentToContentBuffer("<table
style=\"border:1px solid black;\" ><tr><td>row 1 col 1</td><td>row 1 col
2</td></tr><tr><td style=\"background-color:yellow\">row 2 col
1</td><td>row 2 col 2</td></tr></table> with page break after the
table");
//Insert another page break...
pdfGenerator.addPageBreakToContentBuffer();
pdfGenerator.appendHTMLContentToContentBuffer("<h1
style=\"border-bottom:1px solid orange;\">Some other text here and the
beginning of the Docx file:</h1>");
....
//Insert another page break and change the Page Header and the Page
Footer for this section - after the page break the new Header and Footer
will be applied. Without page break the new Header and Footer
will be applied from the next new page
pdfGenerator.appendAlternativeHeaderToContentBuffer("<h1
style=\"background-color:yellow;color:blue;\">This is a different Page
Header where the Docx file starts</h1>");
pdfGenerator.appendAlternativeFooterToContentBuffer("<i
style=\"color:blue;\">This is different footer with page numbers Page:
<b>@#SferyxPDFGenerator-PageNumber#@</b>
of pages: <b>@#SferyxPDFGenerator-TotalPagesNumber#@</b></i>");
pdfGenerator.addPageBreakToContentBuffer();
....
//Append MS Word Docx file directly to the content buffer and it will be
converted to PDF in the same document
pdfGenerator.appendDocxToContentBuffer(new
java.net.URL("file:///c:/test/demo.docx"));
...
//Append Rich Text Format RTF file directly to the content buffer and it
will be converted to PDF in the same document
pdfGenerator.appendRTFFileToContentBuffer(new
java.net.URL("file:///c:/test/Sample06-1.rtf"));
.....
//Close the content buffer and create the PDF document - there is a
possibility to write it to File, OutputStream etc.
pdfGenerator.closeBufferAndGeneratePDF("c:/test/dynamic.pdf","A4",
"Portrait");
You can download the full code for this example from here:
PDFGeneratorDynamicContentDemo.java and it
is also included in the downloadable demo version of the
Sferyx PDFGenerator Demo.
import sferyx.administration.pdfgenerator.*;
PDFGenerator pdfGenerator=new PDFGenerator();
pdfGenerator.setMarginsForStandardPageFormat (10,10,10,10);
pdfGenerator.setCharset ("utf-8"); //Will embed all fonts
and generate PDF/A compliant file and will add support for non-latin languages.
pdfGenerator.generatePDFFromContent ("This is some text on the first page which can be very long and <b>formatted
with <i>any HTML and CSS tags</i></b>", "c:/pdfgenerator-test1.pdf", "A4", "Portrait");
The PDF Generator supports forced page breaks and you can insert page breaks through the standard CSS properties
like
page-break-before:always,
page-break-after:always, page-break-inside:never by
specifying them inside the document in any HTML element for example in a
<p> as shown in the example below:
import sferyx.administration.pdfgenerator.*;
PDFGenerator pdfGenerator=new PDFGenerator();
pdfGenerator.setMarginsForStandardPageFormat (10,10,10,10);
pdfGenerator.setCharset ("utf-8"); //Will embed all fonts
and generate PDF/A compliant file and will add support for non-latin languages.
pdfGenerator.generatePDFFromContent("This is some text on the first page which can be very long and <b>formatted</b>"+"<p style=\"page-break-before:always\"></p>"+"This is some text on the second page which can have <p>paragraphs, very long and <b>formatted</b></p>", "c:/pdfgenerator-test1.pdf","A4","PORTRAIT");
The PDF Generator is capable also of handling in-line images Base64 encoded into the HTML String and they will be embedded into the PDF as expected:
import sferyx.administration.pdfgenerator.*;
PDFGenerator pdfGenerator=new PDFGenerator();
pdfGenerator.setMarginsForStandardPageFormat (10,10,10,10);
pdfGenerator.setCharset ("utf-8");
Will embed all fonts and generate PDF/A compliant file and will add support for non-latin languages.
pdfGenerator.generatePDFFromContent("<html><body>This is test for <b><span style=\"font-size:14pt; color:#ff0000;\">embedded image </span></b><img src=\"data:image/gif;base64,R0lGODlhFAAUAMT/AO3q6u3n5+ve3.....your...image...here....\" border=\"0\" /></body></html>", "c:/pdfgenerator-test1.pdf","A4","PORTRAIT");
This method will
generate the PDF file from Docx source using the standard
page format string such as "A4", "Letter" etc. and and save the file
to the specified OutputStream or File and page orientation such as
"Portrait" or "Landscape". You can also set the page margins using
the method setMarginsForStandardPageFormat.
import sferyx.administration.pdfgenerator.*;
PDFGenerator pdfGenerator=new PDFGenerator();
pdfGenerator.setMarginsForStandardPageFormat (10,10,10,10);
pdfGenerator.setCharset ("utf-8");
Will embed all fonts and generate PDF/A compliant file and will add support for non-latin languages.
pdfGenerator.generatePDFFromDocxURL ("http://your_url_here.docx", destinationFile, "Letter", "Portrait");
This method will
generate the PDF file from RTF source using the standard page format
string such as "A4", "Letter" etc. and and save the file to
the specified OutputStream and page orientation such as
"Portrait" or "Landscape". You can also set the page margins
using the method setMarginsForStandardPageFormat
import sferyx.administration.pdfgenerator.*;
PDFGenerator pdfGenerator=new PDFGenerator();
pdfGenerator.setMarginsForStandardPageFormat (10,10,10,10);
pdfGenerator.setCharset ("utf-8");
Will embed all fonts and generate PDF/A compliant file and will add support for non-latin languages.
pdfGenerator.generatePDFFromRTFURL ("http://your_url_here.rtf", destinationFile, "Letter", "Portrait");
public void generatePDFFromRTFContentBase64String(String
rtfString, OutputStream outputStream,String standardPageFormat, String
orientation)
Generates PDF automatically for given RTF base64 encoded
string containing Rich Text Format content. It will generate the file using
the given standard page format string such as "A4", "Letter" etc. and and
will save it the file to the given outputStream and page orientation such as
"Portrait" or "Landscape". You can also set the page margins using the
method setMarginsForStandardPageFormat
import sferyx.administration.pdfgenerator.*;
PDFGenerator pdfGenerator=new
PDFGenerator();
pdfGenerator.setMarginsForStandardPageFormat
(10,10,10,10);
pdfGenerator.setCharset
("utf-8");
Will embed all fonts and generate PDF/A compliant file
and will add support for non-latin languages.
pdfGenerator.generatePDFFromRTFContentBase64String
("e1xydGYxXGFuc2lcZGVmZjBccGFyIFRoaXMgaXMgYmFzZTY0ZW5jb2RlZCBSVEYgU3RyaW5nXHBhcn0=",
outputStream, "Letter",
"Portrait");
public void
generatePDFFromRTFContentBase64String(String rtfString, OutputStream
outputStream, java.awt.print.PageFormat pageFormat)
Generates PDF automatically for given RTF base64 encoded
string containing Rich Text Format content. It will generate the file
using the given java.awt.print.PageFormat
and and will save it the file to the given outputStream.
import sferyx.administration.pdfgenerator.*;
PDFGenerator pdfGenerator=new
PDFGenerator();
pdfGenerator.setCharset
("utf-8");
Will embed all fonts and generate PDF/A compliant file
and will add support for non-latin languages.
pdfGenerator.generatePDFFromRTFContentBase64String
("e1xydGYxXGFuc2lcZGVmZjBccGFyIFRoaXMgaXMgYmFzZTY0ZW5jb2RlZCBSVEYgU3RyaW5nXHBhcn0=",
outputStream, pageFormat);
public void generatePDFFromRTFInputStream(InputStream
inputStream, OutputStream outputStream,String standardPageFormat, String
orientation)
Generates PDF automatically for given RTF
InputStream containing Rich Text Format content. It will generate
the file using the given standard page format string such as "A4",
"Letter" etc. and and save the file to the given outputStream and
page oriantation such as "Portrait" or "Landscape". You can also set
the page margins using the method setMarginsForStandardPageFormat
import sferyx.administration.pdfgenerator.*;
PDFGenerator pdfGenerator=new PDFGenerator();
pdfGenerator.setMarginsForStandardPageFormat (10,10,10,10);
pdfGenerator.setCharset ("utf-8");
Will embed all fonts and generate PDF/A compliant file and will add support for non-latin languages.
pdfGenerator.generatePDFFromRTFInputStream (inputStream,
outputStream, "Letter", "Portrait");
public void generatePDFFromRTFInputStream(InputStream
inputStream, OutputStream outputStream, java.awt.print.PageFormat
pageFormat)
Generates PDF automatically for given RTF InputStream
containing Rich Text Format RTF. It generates the file using the given
PageFormat and saves it to given OutputStream.
import sferyx.administration.pdfgenerator.*;
PDFGenerator pdfGenerator=new PDFGenerator();
pdfGenerator.setCharset ("utf-8");
Will embed all fonts and generate PDF/A compliant file and will add support for non-latin languages.
pdfGenerator.generatePDFFromRTFInputStream (inputStream,
outputStream, pageFormat);
It will
generate the file using the standard page format
string such as "A4", "Letter" etc. and and save the file to
the specified OutputStream and page orientation such as
"Portrait" or "Landscape". You can also set the page margins
using the method setMarginsForStandardPageFormat
If you need you can use
also OutputStream if
necessary to save the resulting PDF file:
pdfGenerator.generatePDFFromURL ("http://your_url_here", destinationStream, "Letter", "Portrait");
If you want to
include automatically all TTF fonts inside the PDF/A document
or you are using non western languages or special characters you should use the
following method:
pdfGenerator.setCharset ("utf-8");
For
generation of documents in Chinese language use the
following setting:
pdfGenerator.setCharset
("ISO-10646-UCS-2");
Generates
or Converts HTML to PDF automatically for the URL. It will generate
the file using the java.awt.print.PageFormat and save the file to the
specified OutputStream. You can also set the page margins using the
method setMarginsForStandardPageFormat
pdfGenerator.generatePDFFromContent ("<html>your <b>HTML content</b> here</html>", destinationStream, new java.awt.print.PageFormat());
Generates or Converts HTML to PDF automatically for the html content. It
will generate the file using the page format string such as "A4", "Letter"
etc. and page orientation such as "Portrait" or
"Landscape" and save the file to
the specified java.io.OutputStream.
pdfGenerator.generatePDFFromContent ("<html>your <b>HTML content</b> here</html>", destinationStream, "Letter", "Portrait");
It will
generate the file using the given standard page format
string such as "A4", "Letter" etc. and and save the file to
the given OutputStream and page orientation such as
"Portrait" or "Landscape". You can also set the page margins
using the method setMarginsForStandardPageFormat
pdfGenerator.setMarginsForStandardPageFormat (10,10,10,10);
pdfGenerator.generatePDFFromPlainTextContent ("your text content here", destinationStream, "Letter", "Portrait");
It
will generate the file using the given java.awt.PageFormat
object and and saves the file to
the specified OutputStream. The page margins are retrieved
from the java.awt.print.PageFormat object:
pdfGenerator.generatePDFFromPlainTextContent ("your
Plain Text content here", destinationStream, new java.awt.print.PageFormat());
Generates or converts PDF
automatically for the URL source. It will display a PageFormat dialog and file dialog for saving the generated
file
pdfGenerator.generatePDFFromURL ("http://your_url_here");
It will display a PageFormat dialog and save the file to the
specified destination
file
pdfGenerator.generatePDFFromURL ("http://your_url_here","c:/pdfgenerator-test1.pdf");
Generates or converts PDF
automatically for the URL source. It will generate the file
using the given java.awt.print.PageFormat and save the file to the
given destination file
pdfGenerator.generatePDFFromURL ("http://your_url_here", "c:/pdfgenerator-test1.pdf", new java.awt.print.PageFormat());
Generates or converts PDF
automatically for the html content. It will generate the
file using the given standard page format string such
as "A4", "Letter" etc. and and save the file to the given
File and page orientation such as "Portrait" or "Landscape".
You can also set the page margins using the method setMarginsForStandardPageFormat
pdfGenerator.generatePDFFromURL ("http://your_url_here", "c:/pdfgenerator-test1.pdf", "A4", "Portrait");
or
pdfGenerator.generatePDFFromURL ("http://your_url_here", "c:/pdfgenerator-test1.pdf", "Letter", "Landscape");
It will generate the
file using the given standard page format string such as
"A4", "Letter" etc. and and save the file to the given File
and page orientation such as "Portrait" or "Landscape". You
can also set the page margins using the method
setMarginsForStandardPageFormat
pdfGenerator.generatePDFFromPlainTextContent ("some text here", "c:/pdfgenerator-test1.pdf", "Letter", "Landscape");
It will generate the
file using the standard page format string such as
"A4", "Letter" etc. and and save the file to the
specified File
and page orientation such as "Portrait" or "Landscape". You
can also set the page margins using the method
setMarginsForStandardPageFormat
pdfGenerator.generatePDFFromContent ("some <b>HTML</b> content here", "c:/pdfgenerator-test1.pdf", "Letter", "Landscape");
For DOCX and RTF documents the First Page Header and
First Page Footer and all Headers and Footers will be retrieved
automatically from the document. You can override these headers and
footers using the methods here below.
The parameter content can be any plain
text or HTML string - it will be parsed and rendered as a
header on the pages. You can include any HTML element such
as images, tables, colors etc. Keep in mind to adjust the
top margin in order to make enough room for the header if
necessary. If you wish to include also page numbers it
is sufficient to include the @#SferyxPDFGenerator-PageNumber#@ directive anywhere inside your HTML content - it will be parsed
automatically and displayed.
pdfGenerator.setHeader ("<h1 style=\"color:red;background-color:yellow;border:1px solid blue;\">This is a Header - you can put any HTML here</h1>");
pdfGenerator.setHeader ("<h1 style=\"color:red;background-color:yellow;border:1px solid blue;\">This is a Header - you can put any HTML here</h1><p
align=center style=\"padding-top:30px;border-top:1px solid
#0000FF;\"><font face=\"arial\" color=\"blue\">Page:
@#SferyxPDFGenerator-PageNumber#@</font> - you can put any HTML here
</p>");
If you need to include also the total page number, then you
should use the following directive inside the HTML content:
@#SferyxPDFGenerator-TotalPagesNumber#@ - an example of the usage is here
below:
pdfGenerator.setHeader ("<h1 style=\"color:red;background-color:yellow;border:1px solid blue;\">This is a Header - you can put any HTML here</h1><p
align=center style=\"padding-top:30px;border-top:1px solid
#0000FF;\"><font face=\"arial\" color=\"blue\">Page:
@#SferyxPDFGenerator-PageNumber#@ of pages: <b>@#SferyxPDFGenerator-TotalPagesNumber#@</b></font> - you can put
any HTML here </p>");
The parameter content can be any plain
text or HTML string - it will be parsed and rendered as a
header on the pages. You can include any HTML element such
as images, tables, colors etc. Keep in mind to adjust the
top margin in order to make enough room for the header if
necessary. If you wish to include also page numbers it
is sufficient to include the @#SferyxPDFGenerator-PageNumber#@ directive anywhere inside your HTML content - it will be parsed
automatically and displayed.
pdfGenerator.setFirstPageHeader ("<h1 style=\"color:red;background-color:yellow;border:1px solid blue;\">This
is the First Page Header - you can put any HTML here</h1>");
pdfGenerator.setFirstPageHeader ("<h1 style=\"color:red;background-color:green;border:1px solid blue;\">This is
the First Page Header - you can put any HTML here</h1><p
align=center style=\"padding-top:30px;border-top:1px solid
#0000FF;\"><font face=\"arial\" color=\"blue\">Page:
@#SferyxPDFGenerator-PageNumber#@</font> - you can put any HTML here
</p>");
If you need to include also the total page number, then you
should use the following directive inside the HTML content:
@#SferyxPDFGenerator-TotalPagesNumber#@ - an example of the usage is here
below:
pdfGenerator.setFirstPageHeader ("<h1 style=\"color:red;background-color:green;border:1px solid blue;\">This
is the First Page Header - you can put any HTML here</h1><p
align=center style=\"padding-top:30px;border-top:1px solid
#0000FF;\"><font face=\"arial\" color=\"blue\">Page:
@#SferyxPDFGenerator-PageNumber#@ of pages: <b>@#SferyxPDFGenerator-TotalPagesNumber#@</b></font> - you can put
any HTML here </p>");
The parameter content can be any plain
text or HTML string - it will be parsed and rendered as a
footer on the pages. You can include any HTML element such
as images, tables, colors etc. Keep in mind to adjust the
bottom margin in order to make enough room for the footer if
necessary. If you wish to include also page numbers it is
sufficient to include the @#SferyxPDFGenerator-PageNumber#@ directive
anywhere inside your HTML content - it will be parsed automatically and
displayed.
pdfGenerator.setFooter ("<h3 style=\"color:blue;background-color:yellow:border-top:2px
solid green;\">This is a Footer - you can put any HTML here </h3>");
pdfGenerator.setFooter ("<h3 style=\"color:blue;background-color:yellow:border-top:2px
solid green;\">This is a Footer - you can put any HTML here </h3><p
align=center style=\"padding-top:30px;border-top:1px solid
#0000FF;\"><font face=\"arial\" color=\"blue\">Page:
@#SferyxPDFGenerator-PageNumber#@</font> - you can put any HTML here
</p>");
If you need to include also the total page number, then you
should use the following directive inside the HTML content:
@#SferyxPDFGenerator-TotalPagesNumber#@ - an example of the usage is here
below:
pdfGenerator.setFooter ("<h3
style=\"color:blue;background-color:yellow:border-top:2px solid
green;\">This is a Footer - you can put any HTML here </h3><p
align=center style=\"padding-top:30px;border-top:1px solid
#0000FF;\"><font face=\"arial\" color=\"blue\">Page:
@#SferyxPDFGenerator-PageNumber#@ of pages: <b>@#SferyxPDFGenerator-TotalPagesNumber#@</b></font> - you can put
any HTML here </p>");
Specifies to automatically
discard all pages that do not contain text and are
practically a blank pages.
pdfGenerator.setDiscardEmptyPages (true);
For DOCX and RTF documents the Page Numbers formatting
will be retrieved automatically from the document. You can use the
methods below to provide your own formatting when needed.
The parameter content can be any plain
text or HTML string - it will be parsed and rendered
practically as footer in the pages and will parse the
special directive @#SferyxPDFGenerator-PageNumber#@ in
order to place the page number inside the custom formatting.
You can include any HTML element such as images, tables,
colors etc. Keep in mind to adjust the top margin in order
to make enough room for the page numbering if necessary.
pdfGenerator.setGeneratePageNumbers(true,"<p align=center style=\"padding-top:30px;border-top:1px solid #0000FF;\"><span
style=\"font-family:arial;color:blue\">Page: @#SferyxPDFGenerator-PageNumber#@
of total pages <b>@#SferyxPDFGenerator-TotalPagesNumber#@</b></span> - you can put any HTML here </p>");
If set to true, the PDFGenerator
will try to not break tables when page break is encountered
if the table is not longer than the page height. The default
value is false pdfGenerator.setDoNotBreakTablesAcrossPages (true);
If set to true, the PDFGenerator
will try to not break table rows when page break is encountered
if the table is not longer than the page height. The default
value is false pdfGenerator.setDoNotBreakTableRowsAcrossPages (true);
If set to true, the PDFGenerator
will try to not break lists when page break is encountered
if the list is not longer than the page height. The default
value is false
pdfGenerator.setDoNotBreakListsAcrossPages (boolean disablebreak);
Further you can manage the page breaks through the standard
CSS properties
page-break-before:always,
page-break-after:always, page-break-inside:never, by
specifying them inside the document for example in a <div> like this:
<div style="page-break-before:always">some text</div>
or inside tables:
<table style="page-break-after:always">some text ...</table>
or
inside paragraphs:
<p style="page-break-inside:never">some text...</p>
You can easily execute the PDFGenerator.jar from the
command line and perform document conversions without
writing code using the available command line arguments
as follows:
Usage:
java -jar PDFGenerator.jar absolute_url destination_file [page_format] [page_orientation]
[character_set]Example:
C:\test>java -jar "C:\test\PDFGenerator.jar" http://your_url_here
c:/test/test-html.pdf A4 Portrait utf-8
Package
sferyx. administration. pdfgenerator
Fully featured easy-to-use PDF Generator from HTML
and plain text content
Class
Summary |
CustomPageFormat |
This class provides a simplified way for assigning
standard page formats |
PDFGenerator |
General purpose PDF Generator - this class
provides fully featured generation of PDF files from
various sources containing HTML, Word Docx, images or plain text content. |
PDFGeneratorOracleBean |
This class has been optimized to deliver correct
generation of Rich Text content for Oracle Reports and
provide general PDF generation capabilities for
OracleForms. |
Method Summary |
void |
addFileAttachmentToContentBuffer(String htmlContent, java.net.URL fileAttachment)
Adds file attachment with the specified content to describe the attached file - it can be any HTML formatted string. This method should be used in conjuction with openContentBuffer() and closeBufferAndGeneratePDF(). |
void |
addPageBreakToContentBuffer()
Adds a page break to the content buffer and all the content appended after that will be on the next page |
void |
appendAlternativeHeaderToContentBuffer(java.lang.String content)
Sets alternative Page Header to be used for the pages to follow - it can contain any HTML formatting. This Page Header will be active until new one is set. If you want to create new page with new Page Header, set the Page Header first using this method and after that add page break. This should be used in
conjunction with openContentBuffer() and closeBufferAndGeneratePDF(). |
void |
appendAlternativeFooterToContentBuffer(java.lang.String content)
Sets alternative Page
Footer to be used for the pages to follow - it can contain any HTML formatting. This Page
Footer will be active until new one is set. If you want to create new page with new Page
Footer, set the Page Footer first using this method and after that add page break. This should be used in
conjunction with openContentBuffer() and closeBufferAndGeneratePDF(). |
void |
appendDocxToContentBuffer(java.io.File file)
Appends the whole content of the Docx file from the File to the content buffer |
void |
appendDocxToContentBuffer(java.net.URL file)
Appends the whole content of the Docx file from the given URL to the content buffer |
void |
appendHTMLContentToContentBuffer(java.lang.String content)
Appends new string to existing content buffer. |
void |
appendPlainTextContentToContentBuffer(java.lang.String content)
Appends the Plain Text string content to the content buffer |
void |
appendRTFBase64EncodedStringToContentBuffer(java.lang.String base64EncodedRTFString)
Appends RTF content encoded as Base64 string to the content buffer |
void |
appendRTFFileToContentBuffer(java.io.InputStream is)
Appends RTF file from the InputStream to the content buffer |
void |
appendRTFFileToContentBuffer(java.net.URL file)
Appends RTF file from the URL to the content buffer |
void |
clearContentBuffer()
Closes the content buffer and clears the content |
void |
closeBufferAndGeneratePDF(java.io.OutputStream destinationStream,
java.awt.print.PageFormat pageFormat)
Generates pdf automatically for given content buffer created prevuiously by using openContentBuffer() and appendContentXXX() methods. |
void |
closeBufferAndGeneratePDF(java.io.OutputStream destinationStream,
java.lang.String standardPageFormat,
java.lang.String orientation)
Closes the existing content buffer and inserts its content inside the editor. |
void |
closeBufferAndGeneratePDF(java.lang.String destinationFile,
java.lang.String standardPageFormat,
java.lang.String orientation)
Generates pdf automatically for given content buffer created prevuiously by using openContentBuffer() and appendContentXXX() methods. |
void |
generatePDFFromContent (String htmlContent, java.io.OutputStream destinationStream,
String standardPageFormat,
String orientation)
Generates
PDF automatically for given html
content. |
void |
generatePDFFromContent (String htmlContent,
java.io.OutputStream destinationStream, java.awt.print.PageFormat pageFormat)
Generates PDF automatically for given html
content. |
void |
generatePDFFromContent (String htmlContent,
String destinationFile, String standardPageFormat,
String orientation)
Generates PDF automatically for given html
content. |
void |
generatePDFFromPlainTextContent (String content,
java.io.OutputStream destinationStream,
String standardPageFormat,
String orientation)
Generates pdf automatically for given text
content. |
void |
generatePDFFromPlainTextContent (String content,
java.io.OutputStream destinationStream, java.awt.print.PageFormat pageFormat)
Generates pdf automatically for given text
content. |
void |
generatePDFFromPlainTextContent (String content,
String destinationFile, String standardPageFormat,
String orientation)
Generates PDF automatically for given text
content. |
void |
generatePDFFromURL (String sourceURL)
Generates PDF automatically for given URL
source. |
void |
generatePDFFromURL (String sourceURL,
java.io.File destinationFile,
java.awt.print.PageFormat pageFormat)
Generates PDF automatically for given URL
source. |
void |
generatePDFFromURL (String sourceURL,
java.io.OutputStream destinationStream,
java.awt.print.PageFormat pageFormat)
Generates pdf automatically for given URL
source. |
void |
generatePDFFromURL(String sourceURL,
String destinationFile)
Generates PDF automatically for given URL
source. |
void |
generatePDFFromURL(String sourceURL,
String destinationFile,
java.awt.print.PageFormat pageFormat)
Generates PDF automatically for given URL
source. |
void |
generatePDFFromURL (String sourceURL,
String destinationFile, String standardPageFormat,
String orientation)
Generates PDF automatically for given URL
source. |
void |
public void
generatePDFFromRTFContentBase64String(String
rtfString, OutputStream outputStream,String
standardPageFormat, String orientation)
- Generates PDF automatically for given RTF base64
encoded string containing Rich Text Format content.
It will generate the file using the given standard
page format string such as "A4", "Letter" etc. and
save the file to the given outputStream and page
orientation such as "Portrait" or "Landscape". You
can also set the page margins using the method
setMarginsForStandardPageFormat |
void |
public void
generatePDFFromRTFContentBase64String(String
rtfString, OutputStream outputStream,
java.awt.print.PageFormat pageFormat)
- Generates PDF automatically for given RTF base64
encoded string containing Rich Text Format content.
It will generate the file using the given
java.awt.print.PageFormat pageFormat and save the
file to the given outputStream. |
void |
generatePDFFromRTFInputStream(InputStream
inputStream, OutputStream outputStream,String
standardPageFormat, String orientation)
- Generates PDF automatically for given RTF
InputStream containing Rich Text Format content. It
will generate the file using the given standard page
format string such as "A4", "Letter" etc. and and
save the file to the given outputStream and page
orientation such as "Portrait" or "Landscape". You
can also set the page margins using the method
setMarginsForStandardPageFormat. |
void |
generatePDFFromRTFInputStream(InputStream
inputStream, OutputStream outputStream,
java.awt.print.PageFormat pageFormat)
- Generates PDF automatically for given RTF
InputStream containing Rich Text Format RTF. It
generate the file using the given PageFormat and
save to given OutputStream. |
void |
public void
generatePDFFromDocxURL (String
sourceURL, String destinationFile,String
standardPageFormat, String orientation)
throws FileNotFoundException,
java.net.MalformedURLException -
Generates pdf automatically for given URL source
containing a MS Word Docx file. It will generate the
file using the given standard page format string
such as "A4", "Letter" etc. and and save the file to
the given File and page orientation such as
"Portrait" or "Landscape". You can also set the page
margins using the method
setMarginsForStandardPageFormat |
void |
public void
generatePDFFromDocxURL (String
sourceURL, File destinationFile,
java.awt.print.PageFormat pageFormat)
throws FileNotFoundException,
java.net.MalformedURLException -
Generates pdf automatically for given URL source
containing a MS Word Docx file. It generate the file
using the given PageFormat and save the file to the
given File
|
void |
public void
generatePDFFromRTFURL (String
sourceURL, String destinationFile,String
standardPageFormat, String orientation)
throws FileNotFoundException,
java.net.MalformedURLException -
Generates pdf automatically for given URL source
containing Rich Text Format RTF file. It will
generate the file using the given standard page
format string such as "A4", "Letter" etc. and and
save the file to the given File and page orientation
such as "Portrait" or "Landscape". You can also set
the page margins using the method
setMarginsForStandardPageFormat |
void |
public void
generatePDFFromRTFURL (String
sourceURL, File destinationFile,
java.awt.print.PageFormat pageFormat)
throws FileNotFoundException,
java.net.MalformedURLException -
Generates pdf automatically for given URL source
containing Rich Text Format RTF file. It generate
the file using the given PageFormat and save the
file to the given File |
void |
setCharset(String charset)
Set character set for proper PDF
generation in non western languages - for all
languages use UTF-8 - it will embed all fonts inside
the PDF and will generate PDF/A files. For Chinese use
ISO-10646-UCS-2
|
void |
setMarginsForStandardPageFormat (int top, int bottom,
int left, int right)
Sets the margins to be used when the page
format is set using the standard string like "A4" or
"Letter" - this values will not be considered it
PageFormat object is used to set the page format |
void |
setPDFAComplianceEnabled(boolean enabled)
Sets the PDF/A standard compliance - the default is true - to generate PDF/A compliant files you have to enable also the embedding of all fonts inside the document with setCharset("utf-8") |
boolean |
isPDFAComplianceEnabled()
Returns whether the PDF/A standard compliance is enabled or not. |
void |
setScaleToFitWidth (boolean scale)
Indicates whether to rescale the page in
order to fit the given PageFormat - the default is
true |
void |
setHeader (String
content)
Generates the
header for each page in the document. The parameter
content can be any plain text or HTML string - it
will be parsed and rendered as a header on the
pages. You can includes any HTML element such as
images, tables, colors etc. Keep in mind to adjust
the top margin in order to make enough room for the
header if necessary. If you wish to include also
page numbers it is sufficient to include the
@#SferyxPDFGenerator-PageNumber#@ directive anywhere
inside your HTML content - it will be parsed
automatically and displayed. If you need to include
also the total page number, then you should use the
following directive inside the HTML content:
@#SferyxPDFGenerator-TotalPagesNumber#@ - see the
provided examples for major details. |
void |
setFirstPageHeader (String
content)
Generates the
first page header for the document. The parameter
content can be any plain text or HTML string - it
will be parsed and rendered as a header on the
pages. You can includes any HTML element such as
images, tables, colors etc. Keep in mind to adjust
the top margin in order to make enough room for the
header if necessary. If you wish to include also
page numbers it is sufficient to include the
@#SferyxPDFGenerator-PageNumber#@ directive anywhere
inside your HTML content - it will be parsed
automatically and displayed. If you need to include
also the total page number, then you should use the
following directive inside the HTML content:
@#SferyxPDFGenerator-TotalPagesNumber#@ - see the
provided examples for major details. |
void |
setFooter (String
content)
Generates
the footer for each page in the document. The
parameter content can be any plain text or HTML
string - it will be parsed and rendered as a footer
on the pages. You can includes any HTML element such
as images, tables, colors etc. Keep in mind to
adjust the bottom margin in order to make enough
room for the footer if necessary. If you wish to
include also page numbers it is sufficient to
include the @#SferyxPDFGenerator-PageNumber#@
directive anywhere inside your HTML content - it
will be parsed automatically and displayed. If you
need to include also the total page number, then you
should use the following directive inside the HTML
content: @#SferyxPDFGenerator-TotalPagesNumber#@ -
see the provided examples for major details. |
void |
setDiscardEmptyPages (boolean discard)
Specifies to automatically discard all pages that do
not contain text and are practically a blank pages. |
void |
setTTFFontFolderName (String folderName)
- sets the absolute path to the
folder which contains the TrueType fonts to be used
when generating the PDF documents. Please make sure
that this feature is enabled by setting the
character set to UTF-8 |
String |
getTTFFontFolderName()
- returns the name of the True Type fonts
if previously set. Otherwise it will return null and
for the generation of the PDF files will be used the
system font folders. |
void |
setDoNotBreakListsAcrossPages (boolean
disablebreak) - if set to true, the
PDFGenerator will try to not break tables when page
break is encountered if the table is not longer than
the page height. |
void |
setDoNotBreakTablesAcrossPages (boolean
disablebreak) - if set to true, the
PDFGenerator will try to not break tables when page
break is encountered if the table is not longer than
the page height. |
void |
setDoNotBreakTableRowsAcrossPages (boolean
disablebreak) - if set to true, the
PDFGenerator will try to not break table rows when page
break is encountered if the table row is not longer than
the page height. |
boolean |
isDoNotBreakListsAcrossPages()
returns whether the PDFGenerator should not allow to
the lists to break across the pages |
boolean |
isDoNotBreakTablesAcrossPages()
returns whether the PDFGenerator should not allow to
the tables to break across the pages |
void |
setGeneratePageNumbers (boolean generate, String text)
Generates page
numbers for each page in the document. The parameter
content can be any plain text or HTML string - it
will be parsed and rendered practically as footer in
the pages and will parse the special directive "@#SferyxPDFGenerator-PageNumber#@"
in order to place the page number inside the custom
formatting. You can includes any HTML element such
as images, tables, colors etc. Keep in mind to
adjust the top margin in order to make enough room
for the page numbering if necessary.
Example: <p align=center
style="padding-top:30px; border-top:1px solid
#0000FF;"><font face="arial" color="blue">Page: @#SferyxPDFGenerator-PageNumber#@</font></p> |
|