问题
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