在Android应用中将HTML转换为PDF
问题描述:
是否可以在Android应用程序中使用 jsPdf 将html转换为pdf(而无需使用cordova或电话间隔),并将文件保存在本地设备中??
Is it possible to convert html to pdf using jsPdf in android app ( without using cordova or phone gap) and save the file in device local.?
我尝试过此操作,并且单击按钮的onclick时我正在调用jspdf转换逻辑,但是pdf无法生成.
I tried this and onclick of button i am calling jspdf convertion logic, but pdf is not generating.
在adb日志中,单击按钮后,我看到以下警告.
In adb log I see below waring on click of button.
无法调用确定的Visibility()-从未看到过pid的连接:1153
我正在使用jspdf库Filesaver.js.
I am using jspdf library, Filesaver.js.
答
This class might help you. But to compile, it must be in package ".../java/android/print/"
这是一个简单的代码示例:
Here is a simple code example :
PdfConverter converter = PdfConverter.getInstance();
File file = new File(Environment.getExternalStorageDirectory().toString(), "file.pdf");
String htmlString = "<html><body><p>WHITE (default)</p></body></html>";
converter.convert(getContext(), htmlString, file);
// By now the pdf has been printed in the file.