对 wkhtmltopdf 的调用功能进行包装,方便简化使用

Jhonny Mertz abceb80433 Adding xvfb support 10 лет назад
src abceb80433 Adding xvfb support 10 лет назад
.gitignore 4e2e512b5a Fix compile on current java 10 лет назад
LICENSE 5c32296c22 Initial commit 12 лет назад
README.md abceb80433 Adding xvfb support 10 лет назад
pom.xml fea822c579 Defining test scope for pdfbox and junit dependencies #6 10 лет назад

README.md

Java WkHtmlToPdf Wrapper

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.

Usage

Pdf pdf = new Pdf();

pdf.addPage("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>", PageType.htmlAsString);
pdf.addPage("http://www.google.com", PageType.url);

// 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("--html-header", "file:///header.html"));
pdf.addParam(new Param("--enable-javascript"));

// 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.addPage("http://www.google.com", PageType.url);

pdf.saveAs("output.pdf");

Wrapper options

TODO

Error handling

TODO

License

This project is available under MIT Licence.