Skip to content
Open
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
41 changes: 27 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Access to wkhtmltopdf is performed via JNA, exposed through a Java-friendly laye

This fork:
- Upgrades wkhtmltopdf version to 0.12.6
- adds ARM support for Linux
- Upgrades to JNA 5.12.1 as previous versions could not detect aarch64
- drops 32-bit support entirely
- Supports Windows, MacOS, Debian bullseye, Ubuntu focal and jammy and related

## Get it

Gradle:
```groovy
compile 'io.woo:htmltopdf:1.0.9.6'
compile 'io.woo:htmltopdf:1.0.9.7'
```

Maven:
Expand All @@ -26,39 +26,47 @@ Maven:
</repositories>

<dependency>
<groupId>com.github.MagentaHealth</groupId>
<groupId>com.github.phc007</groupId>
<artifactId>htmltopdf-java</artifactId>
<version>1.0.9.6</version>
<version>1.0.9.7</version>
</dependency>
```

## Getting started

The following examples should be sufficient to get you started, however there
are many more options discoverable by looking into the methods of `HtmlToPdf` and `HtmlToPdfObject`.
The following examples should be sufficient to get you started.

#### Saving HTML as a PDF file
#### Saving a webpage from URL as a PDF file

While default settings will serve in most cases, you will need to enable local file access to save PDF to file.
There are many more options discoverable by looking into the methods of `HtmlToPdf` and `HtmlToPdfObject`.

```java
HashMap<String, String> htmlToPdfSettings = new HashMap<String, String>();
htmlToPdfSettings.put("load.blockLocalFileAccess", "false");
boolean success = HtmlToPdf.create()
.object(HtmlToPdfObject.forHtml("<p><em>Apples</em>, not oranges</p>"))
.convert("/path/to/file.pdf");
.object(HtmlToPdfObject.forUrl("https://github.com/phc007/htmltopdf-java", htmlToPdfSettings))
.convert("/path/to/file.pdf");
```

#### Saving a webpage from URL as a PDF file
#### Saving HTML as a PDF file

```java
HashMap<String, String> htmlToPdfSettings = new HashMap<String, String>();
htmlToPdfSettings.put("load.blockLocalFileAccess", "false");
boolean success = HtmlToPdf.create()
.object(HtmlToPdfObject.forUrl("https://github.com/wooio/htmltopdf-java"))
.object(HtmlToPdfObject.forHtml("<p><em>Apples</em>, not oranges</p>", htmlToPdfSettings))
.convert("/path/to/file.pdf");
```

#### Saving multiple objects as a PDF file

```java
HashMap<String, String> htmlToPdfSettings = new HashMap<String, String>();
htmlToPdfSettings.put("load.blockLocalFileAccess", "false");
boolean success = HtmlToPdf.create()
.object(HtmlToPdfObject.forUrl("https://github.com/wooio/htmltopdf-java"))
.object(HtmlToPdfObject.forHtml("<p>This is the second object...</p>"))
.object(HtmlToPdfObject.forUrl("https://github.com/phc007/htmltopdf-java", htmlToPdfSettings))
.object(HtmlToPdfObject.forHtml("<p>This is the second object...</p>", htmlToPdfSettings))
// ...
.convert("/path/to/file.pdf");
```
Expand All @@ -71,7 +79,7 @@ as an HTTP response or adding it as an email attachment
```java
HtmlToPdf htmlToPdf = HtmlToPdf.create()
// ...
.object(HtmlToPdfObject.forUrl("https://github.com/wooio/htmltopdf-java"));
.object(HtmlToPdfObject.forUrl("https://github.com/phc007/htmltopdf-java"));

try (InputStream in = htmlToPdf.convert()) {
// "in" has PDF bytes loaded
Expand Down Expand Up @@ -108,6 +116,11 @@ It might be worth checking that the following packages are installed:
- freetype
- fontconfig

```
apt-get -qq -y --no-install-recommends install\
ca-certificates fontconfig libc6 libfreetype6 libjpeg62-turbo libpng16-16 libssl1.1 libstdc++6 libx11-6 libxcb1 libxext6 libxrender1 xfonts-75dpi xfonts-base zlib1g
```

## Developer Notes

Useful commands when trying to upgrade library files in `src/main/resources/wkhtmltox`:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'io.woo'
version '1.0.9.6'
version '1.0.9.7'

apply plugin: 'java'
apply plugin: 'maven'
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.MagentaHealth</groupId>
<artifactId>htmltopdf-java</artifactId>
<version>1.0.9.6</version>
<version>1.0.9.7</version>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ else if (Platform.isLinux()) {

String id = osReleaseProperties.getProperty("ID");
String versionCodename = osReleaseProperties.getProperty("VERSION_CODENAME");

if ( osReleaseProperties.containsKey("UBUNTU_CODENAME") ) {
id = "ubuntu";
versionCodename = osReleaseProperties.getProperty("UBUNTU_CODENAME");
}

libPath += "." + id;
libPath += "." + versionCodename;
libPath += Platform.isARM() ? ".arm64" : ".amd64";
Expand Down
Binary file not shown.
Binary file not shown.