Convert easily Docx to PDF in your Java applications
Sferyx JSyndrome PDF Generator and Converter
Advanced Java Docx PDF Generator and Converter component - convert easily Microsoft Word Docx files to PDF and PDF/A
Sferyx PDF Generator Component is an advanced and powerful Java Docx to PDF Converter and Generator component. It can convert easily Microsoft Word Docx to PDF in any Java Application - Java Swing, JavaFX, SWT Eclipse and also Oracle Forms and produces perfectly paginated documents preserving the formatting including the page breaks, headers, footers and the page numbers. With only a few lines of Java code is possible to generate complex PDF files from almost any Word Docx source or location and the resulting PDF can be written to a local file, java.io.OutputStream or shown automatically inside the PDF viewer. The PDF Generator component supports all UTF-8 languages including support for Greek, Arabic, Cyrillic, Hebrew, Farsi, Chinese, Japanese, Hindi, Tamil and more. The Sferyx PDF Generator component is ready for use out of the box and does not depend on external packages.
You can create the files dynamically by adding the content on-the-fly directly inside your application with only a few lines of code and also generate page breaks, headers, footers, page numbers when needed.
Trusted Code Signing Security Certificate
Version 23.0
Sferyx JSyndrome PDF Generator Component Edition : Download Sferyx PDFGenerator - PDFGeneratorDemo.zip
- Pure Java Docx to PDF Generation engine - allows fast and easy PDF creation from various sources and also convert even very complex Docx documents with single line of code - 100% in house development - it does not depend on external packages.
- 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 override and specify the desired page format and margins and whether to scale the content to fit inside the given page format 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, Hinid, 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 easily specify custom Headers, Footers and Page numbers in any formatting and position through full HTML formatting support overriding the ones specified in the document
- Now all hyperlinks inside the Docx 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 component is quite simple - with only a few
lines of code is possible to generate and convert practically
any Docx document to PDF and if needed add custom 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:
Convert Word Docx to PDF in Java from URL to java.io.File
This method will convert the Docx to PDF and will
generate the file 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. The
destinationFile parameter is a
java.io.File object:
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");
or using the file name as String:
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", "c:/pdfgenerator-test1.pdf", "A4", "Portrait");
Here you can find major details on converting Docx to PDF in Java with the Sferyx PDF Generator.
Convert Word Docx to PDF in Java from URL to java.io.OutputStream
It will convert the specified Docx document to PDF using the standard page format string such as "A4", "Letter" etc. and and save it to the specified OutputStream and page orientation such as "Portrait" or "Landscape". You can also set the page margins using the method setMarginsForStandardPageFormat. This method will recognize automatically if the 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, rtx, jpeg, gif, png etc.
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:
For
generation of documents in Chinese language use the
following setting:
Here you can find major details on converting Docx to PDF in Java with the Sferyx PDF Generator.
Convert Word Docx to PDF in Java from URL with different java.awt.print.PageFormat dialog options
Converts
automatically the Docx URL to PDF and generates the file
using the given Page Format and File dialog options. It will display a PageFormat dialog and
File dialog for saving the generated
file. This method will recognize automatically if the 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, rtx, jpeg, gif, png etc.
It will display a PageFormat dialog and save the file to the
specified destination
file. This method will recognize automatically if the 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, rtx, jpeg, gif, png etc.
Generates or converts PDF
automatically for the URL source. It will generate the file
using the given java.awt.PageFormat and save the file to the
given destination file. This method will recognize
automatically if the 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, rtx, jpeg,
gif, png etc.
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
or
Here you can find major details on converting Docx to PDF in Java with the Sferyx PDF Generator.
Generate Custom Header for each page in the PDF document
For DOCX 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 described 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.
Generate Custom Header with Page Numbers for each page in the PDF document
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:
Generate First Page Header for the first page of 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 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.
Generate First Page Header with Page Numbers and Total Pages in the PDF document
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:
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 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.
Generate Footer with Page Numbers for each page in the PDF document
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:
Specifies to automatically discard all pages that do not contain text and are practically a blank pages.
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 to adjust the top margin in order to make enough room for the page numbering if necessary.
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
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
Avoid breaking lists 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
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:
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 |
|
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 | License | Demo
& Download
Copyright © 2001-2024 Sferyx
Srl. All rights reserved. Sferyx and the Sferyx logo are registered trademarks
of Sferyx Srl. http://www.sferyx.com