diff --git a/README.md b/README.md index a1b9922..aae049e 100644 --- a/README.md +++ b/README.md @@ -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: @@ -26,39 +26,47 @@ Maven: - com.github.MagentaHealth + com.github.phc007 htmltopdf-java - 1.0.9.6 + 1.0.9.7 ``` ## 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 htmlToPdfSettings = new HashMap(); +htmlToPdfSettings.put("load.blockLocalFileAccess", "false"); boolean success = HtmlToPdf.create() - .object(HtmlToPdfObject.forHtml("

Apples, not oranges

")) - .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 htmlToPdfSettings = new HashMap(); +htmlToPdfSettings.put("load.blockLocalFileAccess", "false"); boolean success = HtmlToPdf.create() - .object(HtmlToPdfObject.forUrl("https://github.com/wooio/htmltopdf-java")) + .object(HtmlToPdfObject.forHtml("

Apples, not oranges

", htmlToPdfSettings)) .convert("/path/to/file.pdf"); ``` #### Saving multiple objects as a PDF file ```java +HashMap htmlToPdfSettings = new HashMap(); +htmlToPdfSettings.put("load.blockLocalFileAccess", "false"); boolean success = HtmlToPdf.create() - .object(HtmlToPdfObject.forUrl("https://github.com/wooio/htmltopdf-java")) - .object(HtmlToPdfObject.forHtml("

This is the second object...

")) + .object(HtmlToPdfObject.forUrl("https://github.com/phc007/htmltopdf-java", htmlToPdfSettings)) + .object(HtmlToPdfObject.forHtml("

This is the second object...

", htmlToPdfSettings)) // ... .convert("/path/to/file.pdf"); ``` @@ -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 @@ -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`: diff --git a/build.gradle b/build.gradle index 145cf21..88add39 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'io.woo' -version '1.0.9.6' +version '1.0.9.7' apply plugin: 'java' apply plugin: 'maven' diff --git a/pom.xml b/pom.xml index 40857cb..7ae6c93 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.MagentaHealth htmltopdf-java - 1.0.9.6 + 1.0.9.7 diff --git a/src/main/java/io/woo/htmltopdf/wkhtmltopdf/WkHtmlToPdfLoader.java b/src/main/java/io/woo/htmltopdf/wkhtmltopdf/WkHtmlToPdfLoader.java index 0dbc118..9645726 100644 --- a/src/main/java/io/woo/htmltopdf/wkhtmltopdf/WkHtmlToPdfLoader.java +++ b/src/main/java/io/woo/htmltopdf/wkhtmltopdf/WkHtmlToPdfLoader.java @@ -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"; diff --git a/src/main/resources/wkhtmltox/0.12.6/libwkhtmltox.ubuntu.jammy.amd64.so b/src/main/resources/wkhtmltox/0.12.6/libwkhtmltox.ubuntu.jammy.amd64.so new file mode 100644 index 0000000..0c12fde Binary files /dev/null and b/src/main/resources/wkhtmltox/0.12.6/libwkhtmltox.ubuntu.jammy.amd64.so differ diff --git a/src/main/resources/wkhtmltox/0.12.6/libwkhtmltox.ubuntu.jammy.arm64.so b/src/main/resources/wkhtmltox/0.12.6/libwkhtmltox.ubuntu.jammy.arm64.so new file mode 100644 index 0000000..ad32de0 Binary files /dev/null and b/src/main/resources/wkhtmltox/0.12.6/libwkhtmltox.ubuntu.jammy.arm64.so differ