1

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.

justdan0227
  • 1,374
  • 18
  • 48
  • not understand you problem . you want to draw pdf page in webview ? or you want to open pdf page in webview ? – Damodhar Mar 15 '16 at 05:42
  • Neither; I want to create a "report" in a webview and then "draw it" into the page of the PdfDocument and save it as a PDF that I can them email or view with an intent(which I have that view PDF working, I'm just not seeing the text I put into the webview). – justdan0227 Mar 15 '16 at 13:09
  • You should check this question: http://stackoverflow.com/questions/30223117/draw-webview-into-a-canvas-in-android-l – Mikhail Naganov Mar 16 '16 at 00:01
  • Thanks I'll look into that. In the mean time I switched `myTextView.setText(Html.fromHtml("

    Title


    Description here

    "));` and then did a draw on the textview
    – justdan0227 Mar 16 '16 at 16:48

0 Answers0