在Android应用中将HTML转换为PDF [英] HTML to PDF Conversion in android app

查看:1377
本文介绍了在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.

这篇关于在Android应用中将HTML转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆