WebView To Pdf

With this feature, you can directly create Pdf from whatever your WebView is showing.

You can also add contenteditable="true" and have user edit data and create pdf from edited Data. You can just call Utility function: PDFUtil.generatePDFFromWebView(savedPDFFile, webView, callback)

You can see Example Code At: PdfEditorActivity of app.

Example:

// Create Temp File to save Pdf To
final File savedPDFFile = FileManager.getInstance().createTempFile(getApplicationContext(), "pdf", false);
// Generate Pdf From Html
PDFUtil.generatePDFFromWebView(savedPDFFile, webView, new PDFPrint.OnPDFPrintListener() {
    @Override
    public void onSuccess(File file) {
        // Open Pdf Viewer
        Uri pdfUri = Uri.fromFile(savedPDFFile);

        Intent intentPdfViewer = new Intent(PdfEditorActivity.this, PdfViewerActivity.class);
        intentPdfViewer.putExtra(PdfViewerActivity.PDF_FILE_URI, pdfUri);

        startActivity(intentPdfViewer);
    }

    @Override
    public void onError(Exception exception) {
        exception.printStackTrace();
    }
});

Last updated