So I am trying to create a PDF from a Webview. Right now I can create an image from the webview, but I am having some problems to split my document in many pages.
Fi
to create pdf from webview you need android>kitkat -> sdk>=19
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
createWebPrintJob(webView);
} else {
}
}
});
//// Function:
private void createWebPrintJob(WebView webView) {
PrintManager printManager = (PrintManager) this
.getSystemService(Context.PRINT_SERVICE);
PrintDocumentAdapter printAdapter =
webView.createPrintDocumentAdapter();
String jobName = getString(R.string.app_name) + " Print Test";
if (printManager != null) {
printManager.print(jobName, printAdapter,
new PrintAttributes.Builder().build());
}
}
I have problem in create image from webview :))))
WebView has built-in functionality to generate PDF's which is made available by using PrintManager Service specifically for the purpose of printing. But for your specific usecase I would suggest you to write(store) the final output of WebView's PrintAdapter which is a PDF file to a local file and go from there.
This link will walk you through the details and implementation. http://www.annalytics.co.uk/android/pdf/2017/04/06/Save-PDF-From-An-Android-WebView/
You can achieve API level 19(KitKat) compatibility with small tweaks for the above solution.
This should solve your problem but incase you face any issue with the implementation let me know.