Java WkHtmlToPdf Wrapper [![Build Status](https://travis-ci.org/jhonnymertz/java-wkhtmltopdf-wrapper.svg?branch=master)](https://travis-ci.org/jhonnymertz/java-wkhtmltopdf-wrapper)
=========
A Java based wrapper for the [wkhtmltopdf](http://wkhtmltopdf.org/) command line tool. As the name implies, it uses WebKit to convert HTML documents to PDFs.
Requirements
------------
**[wkhtmltopdf](http://wkhtmltopdf.org/) 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`:
```groovy
dependencies {
compile 'com.github.jhonnymertz:java-wkhtmltopdf-wrapper:1.1.13-RELEASE'
}
```
#### Maven
In your `pom.xml`:
```xml
<dependency>
<groupId>com.github.jhonnymertz</groupId>
<artifactId>java-wkhtmltopdf-wrapper</artifactId>
<version>1.1.13-RELEASE</version>
</dependency>
```
Usage and Examples
------------
```java
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
```java
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:
```java
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:
```java
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](https://github.com/jhonnymertz/java-wkhtmltopdf-wrapper/issues/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.
没有合适的资源?快使用搜索试试~ 我知道了~
java-wkhtmltopdf-wrapper:wkhtmltopdf的Java包装器
共30个文件
java:15个
md:5个
enc:2个
需积分: 49 8 下载量 126 浏览量
2021-05-13
11:58:45
上传
评论
收藏 40KB ZIP 举报
温馨提示
Java WkHtmlToPdf包装器 命令行工具的基于Java的包装器。 顾名思义,它使用WebKit将HTML文档转换为PDF。 要求 必须已安装并且可以在您的系统上工作。 包装项目依赖 确保已将Java Wrapper依赖项添加到项目中。 如果您使用的是Gradle / Maven,请参见以下示例: Gradle 在您的build.gradle : dependencies { compile ' com.github.jhonnymertz:java-wkhtmltopdf-wrapper:1.1.13-RELEASE ' } 玛文 在您的pom.xml : < dependency> < groupId>com.github.jhonnymertz</ groupId> < artifactId>java-wkhtmltopdf-wrapper
资源详情
资源评论
资源推荐
收起资源包目录
java-wkhtmltopdf-wrapper-master.zip (30个子文件)
java-wkhtmltopdf-wrapper-master
.travis.yml 9KB
pom.xml 8KB
.deepsource.toml 98B
deploy
secring.gpg.enc 3KB
settings.xml 229B
pubring.gpg.enc 2KB
publish.sh 469B
.github
PULL_REQUEST_TEMPLATE.md 105B
ISSUE_TEMPLATE
bug_report.md 544B
feature_request.md 613B
LICENSE 1KB
CONTRIBUTING.md 334B
src
test
resources
simplelogger.properties 2KB
java
com
github
jhonnymertz
wkhtmltopdf
wrapper
unit
PdfTests.java 4KB
XvfbConfigTests.java 1KB
integration
PdfIntegrationTests.java 5KB
main
java
com
github
jhonnymertz
wkhtmltopdf
wrapper
exceptions
PDFExportException.java 925B
WrapperConfigException.java 216B
WkhtmltopdfConfigurationException.java 296B
Pdf.java 11KB
configurations
WrapperConfig.java 4KB
FilenameFilterConfig.java 384B
XvfbConfig.java 1KB
params
Params.java 984B
Param.java 956B
Symbol.java 290B
page
Page.java 705B
PageType.java 274B
.gitignore 20B
README.md 4KB
共 30 条
- 1
人间发财树
- 粉丝: 27
- 资源: 4560
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0