Required Maven dependencies to generate PDF from HTML- Flying Saucer

359 views
Skip to first unread message

Ezhil

unread,
Oct 4, 2023, 6:47:18 AM10/4/23
to Flying Saucer Users
Team - I am trying to add all the necessary dependencies to my OSGi-compatible application so that I can use Flying Saucer. I have read the Getting Started section on the Flying Saucer GitHub page and added the list of dependencies that are listed, but my application is still generating empty PDFs. I think I may be using the wrong dependencies. Could you please tell me all the required Maven dependencies for Flying Saucer?

Here my the POM dependencies
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-pdf-itext5</artifactId>
<version>9.2.2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-pdf</artifactId>
<version>9.2.2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.apple</groupId>
<artifactId>AppleJavaExtensions</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.6</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.santuario</groupId>
<artifactId>xmlsec</artifactId>
<version>4.0.0-M1</version>
<scope>provided</scope>
</dependency>

Java code
import org.w3c.dom.Document;
import org.xhtmlrenderer.pdf.ITextRenderer;
import org.xml.sax.InputSource;

// Create an ITextRenderer instance
ITextRenderer renderer = new ITextRenderer();

// Convert the InputStream to a String
// String htmlContent = convertInputStreamToString(urlInputStream);
String htmlContent = "<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";

// Set the HTML content as the document ////////////
renderer.setDocumentFromString(htmlContent);

// Render to PDF
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
renderer.layout();
renderer.createPDF(outputStream);
renderer.finishPDF();


Andrei Solntsev

unread,
Oct 4, 2023, 4:02:40 PM10/4/23
to flying-sa...@googlegroups.com
Hi Ezhil!
Are you sure you are not catching and hiding the exception?

When I created a new project with the same dependencies as you described, I got the following error:
java.lang.ClassNotFoundException: com.itextpdf.text.DocumentException

When I removed "<scope>provided</scope>" from all dependencies, 
I got a correct PDF with text "My First Heading   My first paragraph."

Andrei Solntsev


ср, 4 окт. 2023 г. в 13:47, Ezhil <ezh...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Flying Saucer Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flying-saucer-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flying-saucer-users/f3431aff-eeca-4ee9-a0f3-806724b3fd0en%40googlegroups.com.

Ezhil

unread,
Oct 6, 2023, 6:20:12 AM10/6/23
to Flying Saucer Users
Thank you Andrei Solntsev for your input. it works after removing scope attribute.
Reply all
Reply to author
Forward
0 new messages