这个是WkHtmltoPDF的wrapper,本wrapper通过java的jni技术编写, 不需要使用命令行,不需要额外的安装。
使用之前,请首先clone 我的StandAlone工程组, 并且在本地的maven中安装libloader工程。
下面是加载本地类库以及Wrapper的使用的例子。
this is a wrapper of WhtmlToPDF native library with java jni.
we can use this library to convert any html file to a pdf.
by the time you need it , clone my standlongs project first, install the libloader to your native maven repository
this is a test code to show how can you use it:
public class Test {
public static void main(String[] args) {
// Load Narive libs
PlatformLoader loader = new PlatformLoader();
loader.load(new File("dist/WKHtmlPDF.xml"));
// converter is available now
WKHtmlPDFConverter conv = new WKHtmlPDFConverter();
// you can put logger here
conv.setOnProgress(i -> {
System.err.println("Progress is " + i);
});
conv.setOnMesssage(e -> {
System.err.println("Message : " + e);;
});
conv.convert(new File("test.html"), new File("test.pdf"));
conv.convert("<h1>Hello</h1>", new File("Demo.pdf"));
}
}
native类库位于binary内部,如果需要从源码构建,请按照如下方法进行:
安装XCode,以及make,gcc,g++等编译器。
进入binary/MacOS文件夹,执行如下命令。
make -f Makefile library
首先安装MinGW 64,然后将MinGW的bin目录放在系统的环境变量Path中。
进入binary/windows文件夹,执行make.bat
./make
native c++ source code in the binary folder。
open the native/Mac OS,and run the makefile :
make -f Makefile library
open the native/windows and run make.bat
make
本组件只能单线程转换PDF,一个一个的被HTML或者String的执行转换,不能多线程同时操作,因此效率比较有限, 这是因为Qt的渲染只能在Qt的ApplicationThread运行。
由于使用了线程池,所以在关闭应用的时候需要显式的使用System.exit
,或者
调用WKHtmlPDFConverter.close
the wrapper working on a single thread,because render operation must be call on Qt Application thread。
thread pool used in WKHtmlPDFConverter,
please call System.exit
, or WKHtmlPDFConverter.close
when
you want to exit the application
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。