All Projects → jhonnymertz → Java Wkhtmltopdf Wrapper

jhonnymertz / Java Wkhtmltopdf Wrapper

Licence: mit
A Java wrapper for wkhtmltopdf

Programming Languages

java
68154 projects - #9 most used programming language

Labels

Projects that are alternatives of or similar to Java Wkhtmltopdf Wrapper

laravel-mjml
Laravel MJML offers support for rendering MJML syntax into in-line HTML that can be sent within mails.
Stars: ✭ 26 (-89.72%)
Mutual labels:  wrapper
SoundCloud-API
SoundCloud API wrapped into a bunch of classes. Built with Retrofit2 and RxJava2.
Stars: ✭ 63 (-75.1%)
Mutual labels:  wrapper
deno-keyv
A simple, easy to use key-value database wrapper for Deno
Stars: ✭ 16 (-93.68%)
Mutual labels:  wrapper
ffmpeg-progressbar-cli
A colored progress bar for FFmpeg.
Stars: ✭ 140 (-44.66%)
Mutual labels:  wrapper
Dis-Snek
A Python API wrapper for Discord
Stars: ✭ 71 (-71.94%)
Mutual labels:  wrapper
Scrython
A python wrapper for the Scryfall API
Stars: ✭ 87 (-65.61%)
Mutual labels:  wrapper
hugo-wrapper
The universal way to include Hugo binary to your project.
Stars: ✭ 27 (-89.33%)
Mutual labels:  wrapper
BootstraPHP
A Bootstrap wrapper for PHP
Stars: ✭ 24 (-90.51%)
Mutual labels:  wrapper
GodaddyWrapper.Net
.Net GoDaddy API Wrapper in C#
Stars: ✭ 15 (-94.07%)
Mutual labels:  wrapper
Jikan4java
Kotlin wrapper for Jikan, an myanimelist api
Stars: ✭ 27 (-89.33%)
Mutual labels:  wrapper
pastebin-csharp
API client for Pastebin in C#
Stars: ✭ 25 (-90.12%)
Mutual labels:  wrapper
elixir-queue
Queue data structure for Elixir-lang
Stars: ✭ 18 (-92.89%)
Mutual labels:  wrapper
acinerella
FFmpeg wrapper library for audio/video decoding
Stars: ✭ 18 (-92.89%)
Mutual labels:  wrapper
hanami-bootstrap
Bootstrap wrapper for hanami framework.
Stars: ✭ 13 (-94.86%)
Mutual labels:  wrapper
Redshift-Tray
A no-frills GUI for the excellent Redshift, with some optional OS hotkeys
Stars: ✭ 34 (-86.56%)
Mutual labels:  wrapper
tapi-yandex-direct
Python библиотека API Яндекс Директ
Stars: ✭ 35 (-86.17%)
Mutual labels:  wrapper
gpgme
GPGme bindings for Rust
Stars: ✭ 55 (-78.26%)
Mutual labels:  wrapper
instamojo-py
Python library for Instamojo API
Stars: ✭ 39 (-84.58%)
Mutual labels:  wrapper
larafy
Larafy is a Laravel package for Spotify API. It is more like a wrapper for the Spotify API.
Stars: ✭ 53 (-79.05%)
Mutual labels:  wrapper
MojangSharp
A C# wrapper library for Mojang API (no longer actively maintained)
Stars: ✭ 38 (-84.98%)
Mutual labels:  wrapper

Java WkHtmlToPdf Wrapper Build Status

A Java based wrapper for the wkhtmltopdf command line tool. As the name implies, it uses WebKit to convert HTML documents to PDFs.

Requirements

wkhtmltopdf must be installed and working on your system.

Wrapper project dependency

Make sure you have Java Wrapper dependency added to your project.

If you are using Gradle/Maven, see example below:

Gradle

In your build.gradle:

dependencies {
    compile 'com.github.jhonnymertz:java-wkhtmltopdf-wrapper:1.1.13-RELEASE'
}

Maven

In your pom.xml:

<dependency>
    <groupId>com.github.jhonnymertz</groupId>
    <artifactId>java-wkhtmltopdf-wrapper</artifactId>
    <version>1.1.13-RELEASE</version>
</dependency>

Usage and Examples

Pdf pdf = new Pdf();

pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>");
pdf.addPageFromUrl("http://www.google.com");

// Add a Table of Contents
pdf.addToc();

// The `wkhtmltopdf` shell command accepts different types of options such as global, page, headers and footers, and toc. Please see `wkhtmltopdf -H` for a full explanation.
// All options are passed as array, for example:
pdf.addParam(new Param("--no-footer-line"), new Param("--header-html", "file:///header.html"));
pdf.addParam(new Param("--enable-javascript"));

// Add styling for Table of Contents
pdf.addTocParam(new Param("--xsl-style-sheet", "my_toc.xsl"));

// Save the PDF
pdf.saveAs("output.pdf");

Xvfb Support

XvfbConfig xc = new XvfbConfig();
xc.addParams(new Param("--auto-servernum"), new Param("--server-num=1"));

WrapperConfig wc = new WrapperConfig();
wc.setXvfbConfig(xc);

Pdf pdf = new Pdf(wc);
pdf.addPageFromUrl("http://www.google.com");

pdf.saveAs("output.pdf");

wkhtmltopdf exit codes

wkhtmltopdf may return non-zero exit codes to denote warnings, you can now set the Pdf object to allow this:

Pdf pdf = new Pdf();
pdf.addPageFromUrl("http://www.google.com");

pdf.setAllowMissingAssets();
// or:  
pdf.setSuccessValues(Arrays.asList(0, 1));

pdf.saveAs("output.pdf");

Cleaning up temporary files

After the PDF generation, the library automatically cleans up the temporary files created. However, there may be situations in which the Pdf object is created but no PDF is generated. To avoid increasing the temp folder size and having problems, you can force the deletion of all temporary files created by the library by:

Pdf pdf = new Pdf();
pdf.cleanAllTempFiles();

This is not an official Wkhtmltopdf product

This library is not an official Wkhtmltopdf product. Support is available on a best-effort basis via github issue tracking. Pull requests are welcomed.

Bugs

  • Tests are incomplete

Known issues

Output of wkhtmltopdf is being added to resulting pdf (Issue #19)

  • Starting from 1.1.10-RELEASE version, there is a method saveAsDirect(String path), which executes wkhtmltopdf passing the path as output for wkhtmltopdf, instead of the standard input -. This saves the results directly to the specified file path.

Because this library relies on wkhtmltopdf, it does not support concurrent PDF generations.

License

This project is available under MIT Licence.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].