HTML to PDF Conversion in android app

霸气de小男生 提交于 2020-03-27 08:15:51

问题


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.?

I tried this and onclick of button i am calling jspdf convertion logic, but pdf is not generating.

In adb log I see below waring on click of button.

Cannot call determinedVisibility() - never saw a connection for the pid: 1153

I am using jspdf library, Filesaver.js.


回答1:


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.



回答2:


If you are developing for devices with API level 19+, then you can avoid 3rd party library. Please check the following link:

http://developer.android.com/reference/android/print/pdf/PrintedPdfDocument.html

If you are developing for API level below 19, then check the following links:

http://manzzup.blogspot.in/2014/05/creating-pdf-file-from-dynamic-html-in.html

If you strictly want to use jsPdf, then try to use jspdf.debug.js.

Cheers!!!



来源:https://stackoverflow.com/questions/40055979/html-to-pdf-conversion-in-android-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!