Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace iText 2.x by OpenPDF #245

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## 9.4.0 (work in progress) - see https://github.com/flyingsaucerproject/flyingsaucer/milestone/5
* ...
* replace iText 2.x by OpenPDF

## 9.3.2 (released 29.12.2023) - see https://github.com/flyingsaucerproject/flyingsaucer/milestone/4?closed=1
* #216 implement loading resources from classpath (#241)
Expand Down
9 changes: 4 additions & 5 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ http://ant.apache.org/
License: Apache Software License Version 2.0
Not packaged with release; development using version 1.6.x

iText (PDF generation)
http://itextpdf.com/
License: Mozilla Public License Version 1.1
Using version 2.1.7.
Included as lib/iText-2.1.7.jar
OpenPDF (PDF generation)
https://github.com/LibrePDF/OpenPDF
License: Mozilla Public License Version 2.0
License: GNU Lesser General Public License 2.1

iText 5 (PDF generation only used in flying-saucer-pdf-itext5)
http://itextpdf.com/
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ of these, along with the license they each have, is listed in the
New releases of Flying Saucer are distributed through Maven. The available artifacts are:

* `org.xhtmlrenderer:flying-saucer-core` - Core library and Java2D rendering
* `org.xhtmlrenderer:flying-saucer-pdf` - PDF output using iText 2.x
* `org.xhtmlrenderer:flying-saucer-pdf-itext5` - PDF output using iText 5.x
* `org.xhtmlrenderer:flying-saucer-pdf-openpdf` - PDF output using OpenPDF
* `org.xhtmlrenderer:flying-saucer-pdf` - PDF output using OpenPDF (ex. iText 2.x)
* `org.xhtmlrenderer:flying-saucer-pdf-itext5` - PDF output using iText 5.x (iText 5 is EOL)
* `org.xhtmlrenderer:flying-saucer-pdf-openpdf` - not supported anymore (replaced by `flying-saucer-pdf`)
* `org.xhtmlrenderer:flying-saucer-swt` - SWT output
* `org.xhtmlrenderer:flying-saucer-log4j` - Logging plugin for log4j

iText 2.x has unfixed security bugs. New projects should avoid it.


## GETTING STARTED

Expand Down
4 changes: 1 addition & 3 deletions doc/guide/include/common-defines.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ define. fs Flying Saucer

define. css21 "CSS 2.1 Specification":http://www.w3.org/TR/CSS21/

define. itext "iText":http://www.lowagie.com/iText/

define. itext.jar iText-2.0.8.jar
define. OpenPDF (ex. iText) "OpenPDF":https://github.com/LibrePDF/OpenPDF

define. jlogging "java.util.logging":http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/package-summary.html

Expand Down
18 changes: 9 additions & 9 deletions doc/guide/users-guide-r7.xil
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Flying Saucer takes XML and CSS as input (where the CSS might be embedded in the

If rendering to a GUI, hyperlinks work so you can navigate between pages. As with HTML, you can also render forms, capture output, and create interactive applications. In a GUI, Flying Saucer provides a _read-only_ view of the output; we cannot replace a text area, say, or Swing's @JEditorPane@ or @JTextPane@. However, for static content, or content created by you, Flying Saucer can be used for help documents, tutorials, books, splash screens, presentations, and much more.

We can also render to PDF. For PDF, the layout rules come from the CSS. The difference is the rendered output uses the ${itext} library to generate PDF. Note that Flying Saucer supports media types for CSS, allowing you to distinguish between screen and print media, for example.
We can also render to PDF. For PDF, the layout rules come from the CSS. The difference is the rendered output uses the ${OpenPDF} library to generate PDF. Note that Flying Saucer supports media types for CSS, allowing you to distinguish between screen and print media, for example.

Last, we have utility classes to render output to an image file. With this, you could use XML and CSS to layout printable content--for example, a flyer, a poster, business cards, etc.--and save them as ../images you can print out or email. It's also a nice way to create thumbnail or reduced-size ../images of pages.

Expand Down Expand Up @@ -129,24 +129,24 @@ Basic requirements:

* Java Runtime Environment 1.4 or above (or JDK of course)
* core-renderer.jar (our distribution)
* ${itext} (also at "iText PDF":http://itextpdf.sourceforge.net)
* ${OpenPDF} (also at "OpenPDF":https://github.com/LibrePDF/OpenPDF)
* "Ant":http://ant.apache.org if you want to build from source
* Minium antialiasing: Minimum is an anti-aliasing library donated by Julian Scheid. We distribute the JAR for this; don't know of it being posted elsewhere. This is only necessary if you want to use this anti-aliasing approach; the Browser demo shows it in practice, and you may like it better than the Java anti-aliasing support, especially in Java 1.4.

${itext} is not necessary at runtime if you are not generating PDFs, but is necessary for the build to satisfy compile-time dependencies. We include a version with our distribution; you should be able to use a release directly from the ${itext} project, as long as the API is the same.
${OpenPDF} is not necessary at runtime if you are not generating PDFs, but is necessary for the build to satisfy compile-time dependencies. We include a version with our distribution; you should be able to use a release directly from the ${OpenPDF} project, as long as the API is the same.

Flying Saucer includes its own CSS parser. There is currently no adaptor for external parsers--we didn't find any high-quality, actively-maintained ones. However, such an adapter did exists--we used to use the SteadyState CSS parser, so in principle, a different CSS parser could be used.

Most of Flying Saucer does not rely on advanced Java features. It should be usable on alternate Java implementations, such as GNU Classpath or Apache Harmony, but this hasn't been tested. You do need solid Java2D (including font) support.

h3(fs_heading#set_classpath). Setting your Classpath

You only need the @core-renderer.jar@ and the @cssparser-0-9-4-fs.jar@ in your CLASSPATH. If you want PDF output, add @itext-paulo-155.jar@. If you want anti-aliasing using the Minium toolkit, add @minium.jar@. That is all you need for your own programs. You also need an XML parser to be in your classpath, but this already included in recent versions of the JRE. To run the browser or use any of it's support classes you will need the @browser.jar@ file.
You only need the @core-renderer.jar@ and the @cssparser-0-9-4-fs.jar@ in your CLASSPATH. If you want PDF output, add @flying-saucer-pdf.jar@. If you want anti-aliasing using the Minium toolkit, add @minium.jar@. That is all you need for your own programs. You also need an XML parser to be in your classpath, but this already included in recent versions of the JRE. To run the browser or use any of it's support classes you will need the @browser.jar@ file.

To summarize, the easiest CLASSPATH to set is:

* @core-renderer.jar@ (required)
* @itext-paulo-155.jar@
* @flying-saucer-pdf.jar@
* @minium.jar@

h3(fs_heading). Sample Applications
Expand Down Expand Up @@ -347,7 +347,7 @@ p. The basic process is:

That's it! You can now display XHTML and CSS in your Swing applications.

What about AWT or alternate GUI toolkits for Java? Our basic rendering routine writes to a "renderer". Right now we support the concept of rendering to an _output device_. We have two output device implementations: one for Java2D (essentially a canvas, or @Graphics2D@ instance) and the other for PDF (using iText). When we render to a Swing panel, we are still painting on a Java2D canvas, so in principle, you should be able to port this rendering to other 2D output surfaces. If you do, we'd like to hear from you! Just note there is no explicit technical limitation that forces you to use Swing--it's just easy, and easy to make it look good.
What about AWT or alternate GUI toolkits for Java? Our basic rendering routine writes to a "renderer". Right now we support the concept of rendering to an _output device_. We have two output device implementations: one for Java2D (essentially a canvas, or @Graphics2D@ instance) and the other for PDF (using OpenPDF). When we render to a Swing panel, we are still painting on a Java2D canvas, so in principle, you should be able to port this rendering to other 2D output surfaces. If you do, we'd like to hear from you! Just note there is no explicit technical limitation that forces you to use Swing--it's just easy, and easy to make it look good.


_Note: we already have an experimental renderer for SWT contributed by one of our users--contact us on the mailing list for more details. We expect to include this as an optional component in an upcoming release._
Expand Down Expand Up @@ -565,7 +565,7 @@ toc. 4 4 *

h4(fs_heading). How do I add custom or specific fonts?

By default, the iText library only includes a subset of fonts, as do PDF reader applications. You may need to register additional fonts used in your document so they may be included with the PDF.
By default, the OpenPDF library only includes a subset of fonts, as do PDF reader applications. You may need to register additional fonts used in your document so they may be included with the PDF.

For each font you need, make the following call:

Expand All @@ -581,7 +581,7 @@ _Thanks to Sean Wesenberg for this tip._

h4(fs_heading). How do I specify fonts for a specific encoding?

It's actually better, since the ${itext} library provides code to parse font files and return font measurements.
It's actually better, since the ${OpenPDF} library provides code to parse font files and return font measurements.

That said, the default encoding is Latin-1; if your content is encoded differently, you may have problems where certain characters are not recognized and don't appear correctly in the output. You will need to specify a different encoding for a specific font, by registering the font with the @ITextRenderer@ instance you're using before you call @setDocument()@. For example, to support Unicode/UTF-8, you'd need

Expand All @@ -597,7 +597,7 @@ resolver.addFont (
);
}}

Where the font supports Unicode characters (in this example). The @BaseFont@ class in the example comes from the iText library, which you'll of course need in your classpath when compiling.
Where the font supports Unicode characters (in this example). The @BaseFont@ class in the example comes from the OpenPDF library, which you'll of course need in your classpath when compiling.

_Thanks for Manos Bastis for contributing this info and patches._

Expand Down
18 changes: 9 additions & 9 deletions doc/guide/users-guide-r8.xil
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ${fs} takes XML and CSS as input, where the CSS might be embedded in the documen

If rendering to a GUI, hyperlinks are clickable so you can navigate between pages. As with HTML, you can also render forms, capture output, and create interactive applications. In a GUI, ${fs} provides a _read-only_ view of the output; we cannot replace a text area, say, or Swing's @JEditorPane@ or @JTextPane@. However, for static content, or content created by you, ${fs} can be used for help documents, tutorials, books, splash screens, presentations, and much more.

We can also render to PDF. For PDF, the layout rules come from the CSS using the print media qualifier. For PDF output we rely on the ${itext} library to generate PDF. Note that ${fs} supports media types for CSS, allowing you to distinguish between screen and print media, for example.
We can also render to PDF. For PDF, the layout rules come from the CSS using the print media qualifier. For PDF output we rely on the ${OpenPDF} library to generate PDF. Note that ${fs} supports media types for CSS, allowing you to distinguish between screen and print media, for example.

Last, we have utility classes to render output to an image file. With this, you could use XML and CSS to layout printable content--for example, a flyer, a poster, business cards, etc.--and save them as images you can print out or email. It's also a nice way to create thumbnail or reduced-size images of pages.

Expand Down Expand Up @@ -130,25 +130,25 @@ Basic requirements:

* Java Runtime Environment 1.4 or above (or JDK of course)
* core-renderer.jar (our distribution)
* ${itext} (also at "iText PDF":http://itextpdf.sourceforge.net )
* ${OpenPDF} (also at "OpenPDF":https://github.com/LibrePDF/OpenPDF )
* "Ant":http://ant.apache.org if you want to build from source

As a rule, we try to limit our dependencies on external libraries to keep the download size to a minimum.

${itext} is not necessary at runtime if you are not generating PDFs, but is necessary for the build to satisfy compile-time dependencies. We include a version with our distribution; you should be able to use a release directly from the ${itext} project, as long as the API is the same. As of release R8, we target the ${itext} 2.x API.
${OpenPDF} is not necessary at runtime if you are not generating PDFs, but is necessary for the build to satisfy compile-time dependencies. We include a version with our distribution; you should be able to use a release directly from the ${OpenPDF} project, as long as the API is the same. As of release R8, we target the ${OpenPDF} 2.x API.

${fs} includes its own CSS parser. There is currently no adaptor for external parsers--we didn't find any high-quality, actively-maintained ones. However, such an adapter did exist in earlier ${fs} releases--we used to use the SteadyState CSS parser--so in principle, a different CSS parser could be used.

Most of ${fs} does not rely on advanced Java features. It should be usable on alternate Java implementations, such as GNU Classpath or Apache Harmony, but this hasn't been tested. You do need solid Java2D (including font) support.

h3(fs_heading#set_classpath). Setting your Classpath

You only need the @core-renderer.jar@ in your CLASSPATH. If you want PDF output, add @${itext.jar}@. You also need an XML parser to be in your classpath, but this already included in the JDK.
You only need the @core-renderer.jar@ in your CLASSPATH. If you want PDF output, add @${flying-saucer-pdf}@. You also need an XML parser to be in your classpath, but this already included in the JDK.

To summarize, the easiest CLASSPATH to set is:

* @core-renderer.jar@ (required)
* @${itext.jar}@
* @${flying-saucer-pdf.jar}@


h3(fs_heading). Sample Applications
Expand Down Expand Up @@ -349,7 +349,7 @@ p. The basic process is:

That's it! You can now display XHTML and CSS in your Swing applications.

What about AWT or alternate GUI toolkits for Java like SWT? Our basic rendering routine writes to a "renderer". Right now we support the concept of rendering to an _output device_. We have two output device implementations: one for Java2D (essentially a canvas, or @Graphics2D@ instance) and the other for PDF (using iText). When we render to a Swing panel, we are still painting on a Java2D canvas, so in principle, you should be able to port this rendering to other 2D output surfaces. Just note there is no explicit technical limitation that forces you to use Swing--it's just easy, and easy to make it look good.
What about AWT or alternate GUI toolkits for Java like SWT? Our basic rendering routine writes to a "renderer". Right now we support the concept of rendering to an _output device_. We have two output device implementations: one for Java2D (essentially a canvas, or @Graphics2D@ instance) and the other for PDF (using OpenPDF). When we render to a Swing panel, we are still painting on a Java2D canvas, so in principle, you should be able to port this rendering to other 2D output surfaces. Just note there is no explicit technical limitation that forces you to use Swing--it's just easy, and easy to make it look good.

_Note: we already have an experimental renderer for SWT contributed by one of our users--contact us on the mailing list for more details. We expect to include this as an optional component in an upcoming release._

Expand Down Expand Up @@ -577,7 +577,7 @@ toc. 4 4 *

h4(fs_heading). How do I add custom or specific fonts?

By default, the iText library only includes a subset of fonts, as do PDF reader applications. You may need to register additional fonts used in your document so they may be included with the PDF.
By default, the OpenPDF library only includes a subset of fonts, as do PDF reader applications. You may need to register additional fonts used in your document so they may be included with the PDF.

For each font you need, make the following call:

Expand All @@ -593,7 +593,7 @@ _Thanks to Sean Wesenberg for this tip._

h4(fs_heading). How do I specify fonts for a specific encoding?

It's actually better, since the ${itext} library provides code to parse font files and return font measurements.
It's actually better, since the ${OpenPDF} library provides code to parse font files and return font measurements.

That said, the default encoding is Latin-1; if your content is encoded differently, you may have problems where certain characters are not recognized and don't appear correctly in the output. You will need to specify a different encoding for a specific font, by registering the font with the @ITextRenderer@ instance you're using before you call @setDocument()@. For example, to support Unicode/UTF-8, you'd need

Expand All @@ -609,7 +609,7 @@ resolver.addFont (
);
}}

where the font supports Unicode characters (in this example). The @BaseFont@ class in the example comes from the iText library, which you'll of course need in your classpath when compiling.
where the font supports Unicode characters (in this example). The @BaseFont@ class in the example comes from the OpenPDF library, which you'll of course need in your classpath when compiling.

_Thanks to "Manos Batsis":http://github.com/manosbatsis for contributing this info and patches._

Expand Down
5 changes: 0 additions & 5 deletions flying-saucer-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
</licenses>

<dependencies>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>${itext.version}</version>
</dependency>
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

/**
* Opens a frame and displays, for a selected font, the glyphs for a range of Unicode code points. Can be used to
* identify which glyphs are supported by a font. Can export to PDF. Requires core-renderer and iText on classpath.
* identify which glyphs are supported by a font. Can export to PDF. Requires core-renderer and OpenPDF on classpath.
*
* @author Patrick Wright
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ public void actionPerformed(ActionEvent evt) {
}
};
export_pdf.putValue(Action.NAME, "Export PDF...");
//is iText in classpath?
try{
//is OpenPDF in classpath?
try {
Class.forName("com.lowagie.text.DocumentException");
} catch( ClassNotFoundException e )
{
} catch (ClassNotFoundException ignore) {
export_pdf.setEnabled(false);
}

Expand Down
2 changes: 1 addition & 1 deletion flying-saucer-fop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13.3</version>
<version>${itext5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion flying-saucer-pdf-itext5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13.3</version>
<version>${itext5.version}</version>
</dependency>
<dependency>
<groupId>org.xhtmlrenderer</groupId>
Expand Down
Loading