justdan0227
justdan0227

Reputation: 1362

Android Webview to PDF using PdfDocument

When attempting to create a PDF using PdfDocument from a Webview, my content is always blank. Trying a very simple example (writting a report writter) and yet the string does not show up in the PDF. The PDF is getting create, however the text is not showing up.

 WebView webview;

 String summary = "<html><body><h1>A very simple line of <b>text</b> </h1></body></html>";
 webview.setBackgroundColor(Color.RED);
 webview.loadDataWithBaseURL(null, summary,
         "text/HTML", "UTF-8", null);

PdfDocument document = new PdfDocument();
int pageNumber = 1;
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(webview.getWidth(),
                       webview.getHeight(), pageNumber).create();
PdfDocument.Page page = document.startPage(pageInfo);
webview.draw(page.getCanvas());
document.finishPage(page);

I also attempted to place this inside a custom webview and process in public void onPageFinished(WebView view, String url), but still no string shown in PDF.

The PDF is RED.

Upvotes: 1

Views: 1484

Answers (0)

Related Questions