Skip to content

ztomic/wkhtmltopdf-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

This is based on jhonnymertz/java-wkhtmltopdf-wrapper

Requirements

wkhtmltopdf must be installed and working on your system.

Usage

WkHtmlToPdf pdf = new WkHtmlToPdf();

pdf.addSources(Source.from("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>", "UTF-8"));
pdf.addSources(Source.fromUrl("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.addArguments(
	Argument.from(Option.PageOption.EnableJavascript),
	Argument.from(Option.HeaderAndFooterOption.HeaderHtml, "file:///example.html")
);
pdf.addArguments(Option.NoFooterLine.NoFooterLine);

// Save the PDF
pdf.save(Paths.get("output.pdf"));

Maven dependency

<dependencies>
	<dependency>
		<groupId>com.ztomic</groupId>
		<artifactId>wkhtmltopdf-java</artifactId>
		<version>0.0.1</version>
	</dependency>
</dependencies>
<repositories>
	<repository>
		<id>bintray</id>
		<name>bintray</name>
		<url>http://jcenter.bintray.com/</url>
		<snapshots>
			<enabled>false</enabled>
		</snapshots>
	</repository>
</repositories>

About

Java wrapper for wkhtmltopdf

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages