₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,137 members, 8,420,521 topics. Date: Thursday, 04 June 2026 at 11:20 PM

Toggle theme

Android Webview - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingAndroid Webview (1209 Views)

1 Reply

Android Webview by Xcetera(op): 4:31pm On Jul 25, 2015
Hello Android Developers,

Please I have an Issue here wouldn't know if it's small or big.... smiley.
I'm implementing export to PDF in an android app (Someone has already work on a part that loads the content into the webview), the concept I'm using is to convert the content of the webview to an image then attach that image to a PDF file.

The challenge now is that, the image is always empty because the url that's being loaded is via loadBaseURL. However if I do loadURL and parse a url e.g https://www.google.com, once the URL has been successfully loaded, the image is created with the landing page of google.

So I don't know if anyone have an idea of what I'm doing wrong that when using loadBaseURL the image is always white.

Below is the part where I'm trying to capture the content of the webview:

webView.loadDataWithBaseURL("file:///android_asset/", (htmlString + htmlBody), "text/html", "utf8", null);
//webView.loadUrl("http://");
//==========================Export to PDF==========================
webView.setWebViewClient(new WebViewClient() {

@Override
public void onPageFinished(WebView view, String url) {

//Picture webViewShot = view.capturePicture();
webView.setDrawingCacheEnabled(true);
webView.buildDrawingCache();


Bitmap bmp = Bitmap.createBitmap(webView.getWidth(), webView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
//Paint paint = new Paint();
//canvas.drawBitmap(bmp, 0, bmp.getHeight(), paint);
webView.draw(canvas);
System.out.println("Inside onPageFinished" + canvas.getWidth() + " " + canvas.getHeight());
//webView.draw( canvas );

FileOutputStream out = null;
try {
out = new FileOutputStream(IMAGE_FILE);
//out.write(IMAGE_FILE.toString().getBytes());
} catch (FileNotFoundException e) {

e.printStackTrace();
}
bmp.compress(Bitmap.CompressFormat.JPEG, 97, out);
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}

Your kind assistance would be highly appreciated.

Looking forward to your responses.

Thank you very much.
1 Reply

Embed And Play Youtube Video In Android Webview234

Selling Of Some Of My Custom Programmed Application At A Rediculous PriceAsynchronous ES6 With Generators – TutsplusSomeone Should Tutor Us On BASIC, HTML, PHP Programming