Convert easily HTML to PDF in your Java applications

Sferyx JSyndrome PDF Generator and Converter


Advanced Java HTML to PDF Generator and Converter component - create easily PDF and PDF/A documents from any HTML content.

Sferyx PDF Generator Component is a powerful Java HTML to PDF Converter and Generator component. It converts and generates quickly and easily HTML to PDF in any Java Application - Java Swing, JavaFX, SWT Eclipse and also Oracle Forms - including CLOB fields and produces perfectly paginated documents. With only a few lines of code is possible to generate complex PDF files from practically any source or location and the resulting PDF can be written in a file, output stream or shown inside the PDF viewer. Supports all UTF-8 languages including support for all Latin languages, Greek, Arabic, Cyrillic, Hebrew, Farsi, Chinese, Japanese, Hindi, Tamil, Symbol font, Wingdings fonts  and more.

You can create the files dynamically by adding the content on-the-fly directly from your application with only a few lines of code and also generate page breaks, headers, footers and page numbers when needed.

HTML to PDF Java

 

All Sferyx products are signed with  
Trusted Code Signing Security Certificate

Download Sferyx PDFGenerator Component Java HTML to PDF Order Sferyx PDFGenerator Component Java HTML to PDF
Version 23.0

Sferyx JSyndrome PDF Generator Component Edition : Download Sferyx PDFGenerator - PDFGeneratorDemo.zip
 
 

 

  • Pure Java HTML to 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 Java 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 including the inline Base64 encoded images, inline and linked CSS 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 Java Swing, JavaFX, 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

 

Example usage


The use of the PDFGenerator Java HTML to PDF 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:

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");

Dynamically Generate PDF in Java with the Sferyx PDF Generator

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.

Generate PDF directly from HTML Java String content

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");

Generate PDF document with two pages and forced page break

 

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");

Generate PDF automatically from HTML Java String with Base64 encoded images

You can convert HTML Strings which contain embedded images very easily with only few lines of code - it is supported by default and no additional settings are needed. The PDF Generator is capable 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");

Add File Attachment to the PDF Document

The PDF Generator is capable also of adding File Attachments to the PDF document with a single line of code appending it to any position in the document:

import sferyx.administration.pdfgenerator.*;

PDFGenerator pdfGenerator=new PDFGenerator();
pdfGenerator.openContentBuffer ();
pdfGenerator.appendHTMLContentToContentBuffer ("<h1>This is a test PDF file with Attachments</h1>");
//Adds local file attachment to the generated PDF document with some description.
pdfGenerator.addFileAttachmentToContentBuffer ("<b>Sample report attachment:</b>", new java.net.URL("file:///C:/test/sampleReport.pdf"));
//Adds remote file attachment to the generated PDF document with some description.
pdfGenerator.addFileAttachmentToContentBuffer ("<i>Remote image added as attachment:</i>", new java.net.URL("https://some_host/image.jpg"));
//Close the content buffer and generate the PDF document
pdfGenerator.closeBufferAndGeneratePDF ("c:/test/fileAttachmentsTest.pdf","A4","Portrait");


Creating clickable Image icons for File Attachments

There is also the possibility to specify any image as file attachment icon - the image can be local or remote - it will be handled automatcially. You can do it very easily by simply inserting a hyperlink with a specific class  SferyxPDFGeneratorFileAttachment the following way:

pdfGenerator.appendHTMLContentToContentBuffer("<a class=\"SferyxPDFGeneratorFileAttachment\" href=\"file:///absolute_file_attachment_url\"><img src=\"https://sferyx.com/images/logos/fulllogo.jpg\"></a>");

The image will be used to generate a clickable icon for the File Attachment object, while the href attribute will be the file in the File Attachment - it can be any file - it can be local or remote absolute URL and the file will be embedded in the document automatically.

The same way you can generate also a text link for the File Attachment object in the following manner:

pdfGenerator.appendHTMLContentToContentBuffer("<a style=\"text-decoration:none;\" class=\"SferyxPDFGeneratorFileAttachment\" href=\"file:///absolute_file_attachment_url\">This is a file attachment</a>");

If you specify the hyperlink's class to SferyxPDFGeneratorFileAttachment any hyperlink and its href will be converted to a File Attachment - the href reference can be any file - local or remote and it will be embedded automatically into the resulting PDF file.

importrt sferyx.administration.pdfgenerator.*;

PDFGenerator pdfGenerator=new PDFGenerator();
pdfGenerator.openContentBuffer ();
pdfGenerator.appendHTMLContentToContentBuffer ("<h1>This is a test PDF file with Attachments</h1>");
//Adds local file attachment to the generated PDF document with clickable image icon to open the file attachment.
pdfGenerator.addFileAttachmentToContentBufferr ("<a class=\"SferyxPDFGeneratorFileAttachment\" href=\"file:///absolute_file_attachment_url\"><img src=\"https://sferyx.com/images/logos/fulllogo.jpg\"></a>");
///Adds remote file attachment to the generated PDF document with some text link description.
pdfGenerator.addFileAttachmentToContentBuffer ("<a style=\"text-decoration:none;\" class=\"SferyxPDFGeneratorFileAttachment\" href=\"file:///absolute_file_attachment_url\">This is a file attachment</a>");
//Close the content buffer and generate the PDF document
pdfGenerator.closeBufferAndGeneratePDFDF ("c:/test/imageIconFileAttachmentsTest.pdf","A4","Portrait");

 

You can download the full code for these examples from here: FileAttachmentTestPdfGenerator.java and it is also included in the downloadable demo version of the Sferyx PDFGenerator Demo.

Generate PDF automatically from HTML content from URL

The method generatePDFFromURL(String url, java.io.OutputStream stream, String pageSize, String pageOrientation) will generate the PDF file using the standard page format string such as "A4", "Letter" etc. and save the file to the specified java.io.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 java.io.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");


The method generatePDFFromContent(String content, java.io.OutputStream stream, java.awt.print.PageFormat pageFormat)  generates or converts HTML to PDF automatically from the given String which contains HTML formatted content. It will generate the file using the given java.awt.print.PageFormat and and save the file to the specified java.io.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());


The method generatePDFFromContent(String content, java.io.OutputStream stream, String pageSize, String pageOrientation) generates or converts HTML to PDF automatically for the given String with HTML formatted 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");

Generate or convert PDF automatically from URL source and different Page Dialog options


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 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");

Generate PDF automatically from Plain Text Content Java String

It will generate the file using the given standard page format string such as "A4", "Letter" etc. 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");

Generate PDF automatically from HTML Java String content

It will generate the file using the standard page format string such as "A4", "Letter" etc. 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");

Generate Header for each page in the PDF 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 include any HTML element such as images, tables, colors etc. Keep in mind that the the top margin of the page will be adjusted automatically 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>");

Generate Header with Page Numbers for each page in the PDF document

 

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>");

Generate First Page Header for the first page of 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 include any HTML element such as images, tables, colors etc. Keep in mind that the the top margin of the page will be adjusted automatically 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>");

Generate First Page Header with Page Numbers and Total Pages in the PDF document

 

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>");

Generate Footer for each page in the PDF 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 include any HTML element such as images, tables, colors etc. Keep in mind that the the top margin of the page will be adjusted automatically 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.setFooter ("<h3 style=\"color:blue;background-color:yellow:border-top:2px solid green;\">This is a Footer - you can put any HTML here </h3>");

Generate Footer with Page Numbers for each page in the PDF document

 

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);

Generate Page Numbers for each page in the PDF 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 include any HTML element such as images, tables, colors etc. Keep in mind that the the top margin of the page will be adjusted automatically in order to make enough room for the header if necessary.

 

pdfGenerator.setGeneratePageNumbers(true,"<p align=center style=\"padding-top:30px;border-top:1px solid #0000FF;\"><font face=\"arial\" color=\"blue\">Page: @#SferyxPDFGenerator-PageNumber#@ of total pages <b>@#SferyxPDFGenerator-TotalPagesNumber#@</b></font> - you can put any HTML here </p>");

Avoid breaking tables across the pages when possible in the PDF document

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);

Avoid breaking tables rows across the pages when possible in the PDF document

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. The default value is false

pdfGenerator.setDoNotBreakTableRowsAcrossPages (true);

Avoid breaking lists across the pages when possible in the PDF document


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);

Insert Forced and Manual Page Breaks in the PDF document


Further, you can manage the 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 for example in a <div> as follows:

 

<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>

Command line arguments for the PDFGenerator.jar file

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

CustomPageFormatThis class provides a simplified way for assigning standard page formats
PDFGeneratorGeneral purpose PDF Generator - this class provides fully featured generation of PDF files from various sources containing HTML, Word Docx, images or plain text content.
PDFGeneratorOracleBeanThis 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.
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>
 
 

Customers

Sferyx customer base counts more than 1000 corporate customers and institutions from over 40 countries and different industrial sectors as follows: Media and publishing companies, Internet Service Providers, Research  Labs, Fortune 500 companies, Universities, Colleges and Schools, Software Developers, Content Management Systems developers, Web design agencies.

More than 1000 corporate customers, among them:

 

| Home | Users Manual | LicenseDemo & Download

Copyright © 2001-2024 Sferyx Srl. All rights reserved. Sferyx and the Sferyx logo are registered trademarks of Sferyx Srl. http://www.sferyx.com