Skip to content
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
28 changes: 22 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<pdfbox.version>3.0.8</pdfbox.version>
<json.version>20260814</json.version>
<commons-io.version>2.22.0</commons-io.version>
<flying-saucer.version>9.1.22</flying-saucer.version>
<flying-saucer.version>10.5.0</flying-saucer.version>
<guava.version>33.7.1-jre</guava.version>
<jackson.version>2.22.2</jackson.version>
<poi.version>5.5.1</poi.version>
Expand Down Expand Up @@ -168,10 +168,13 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis-ext</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Feature: excel (EmbeddedFileExtractor) -->
<!-- Feature: excel (EmbeddedFileExtractor) -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
Expand Down Expand Up @@ -231,9 +234,22 @@
<optional>true</optional>
</dependency>

<!-- ============================ Test ============================ -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<!-- slf4j-api is required by flying-saucer 10.x -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.17</version>
<scope>test</scope>
</dependency>

<!-- ============================ Test ============================ -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/rsh/jtoolkit/pdf/HTMLToPDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ private HTMLToPDF() {}
public static void generatePDF(String inputHtmlPath, String outputPdfPath) {
try {
String url = new File(inputHtmlPath).toURI().toURL().toString();
ITextRenderer renderer = ITextRenderer.fromUrl(url);
try (OutputStream out = Files.newOutputStream(Paths.get(outputPdfPath))) {
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(out);
}
} catch (IOException e) {
throw new UncheckedIOException("Failed to generate PDF from " + inputHtmlPath, e);
} catch (com.lowagie.text.DocumentException e) {
} catch (org.openpdf.text.DocumentException e) {
throw new IllegalStateException("Failed to render PDF from " + inputHtmlPath, e);
}
}
Expand Down
Loading