Unable to Print or make PDF form WebView.

955 views
Skip to first unread message

Maunik Shah

unread,
Oct 12, 2020, 5:44:17 AM10/12/20
to android-webview-dev
Hello Devs,

I'm using standard print service to save WebView content as pdf or to print. But from the latest update of Android System WebView on Playstore (version: 86.0.4240.75).

With older version of the WebView, it's working fine.

WhatsApp Image 2020-10-10 at 2.36.34 PM.jpeg

Code:
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Initialize member variables
mWebView = findViewById(R.id.web_view);
Button pdf = findViewById(R.id.pdf);

WebView.setWebContentsDebuggingEnabled(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
// mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setDisplayZoomControls(false);
mWebView.setInitialScale(150);

pdf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createPDF();
}
});

loadWebView();
}

private void loadWebView() {
mWebView.loadUrl("http://www.google.com");
}

private void createPDF() {
// Get a PrintManager instance
PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
String jobName = "Document";
// Get a print adapter instance
PrintDocumentAdapter printAdapter;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
printAdapter = mWebView.createPrintDocumentAdapter(jobName);
} else {
printAdapter = mWebView.createPrintDocumentAdapter();
}
// Create a print job with name and adapter instance
PrintAttributes.Builder builder = new PrintAttributes.Builder();
builder.setMediaSize(PrintAttributes.MediaSize.ISO_A4);
printManager.print(jobName, printAdapter, builder.build());
}

Thank you.
Maunik Shah


Maunik Shah

unread,
Oct 12, 2020, 5:54:00 AM10/12/20
to android-webview-dev, Maunik Shah

Torne (Richard Coles)

unread,
Oct 12, 2020, 12:08:46 PM10/12/20
to Maunik Shah, Shimi Zhang, android-webview-dev
+Shimi Zhang is looking into this issue.

--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/android-webview-dev/94f1ab1f-14d2-46b5-b307-e17bf7be86ben%40chromium.org.

Shimi Zhang

unread,
Oct 12, 2020, 12:19:08 PM10/12/20
to Torne (Richard Coles), Maunik Shah, android-webview-dev
Thanks for the report, we are working on crbug.com/1137016 for exactly the same issue.

Maunik Shah

unread,
Oct 13, 2020, 10:50:23 AM10/13/20
to android-webview-dev, Shimi Zhang, Maunik Shah, android-webview-dev, to...@chromium.org
Hello Devs,

Good to hear that it is being tracked internally.
Number of users reporting this is increasing day in day basis and It is kind of our primary dependency in app to be able to print the document.

We would like to know, when can we expect fix for this issue? 

Shimi Zhang

unread,
Oct 13, 2020, 12:38:38 PM10/13/20
to Maunik Shah, android-webview-dev, to...@chromium.org
We got the fix yesterday, we are working on the release, users will gradually get the new release in the next few days I believe.

Manish Raje

unread,
Oct 21, 2020, 5:14:03 AM10/21/20
to android-webview-dev, Shimi Zhang, android-webview-dev, to...@chromium.org, Maunik Shah
Hi, most of our clients are getting this fix as a part of the Webview update on October 13th. However, there is one particular client on whose device the fix isn't working even after the update to the October 13th version as per the client. 

The device in question is Samsung Galaxy Tab A (2017) with Android version 9 and Security patch update till 1st Aug 2020. 

Any pointers please?

Thanks. 

Shimi Zhang

unread,
Oct 21, 2020, 1:40:46 PM10/21/20
to Manish Raje, android-webview-dev, to...@chromium.org, Maunik Shah
Hi Manish,

I'd like to double check if the user got the correct version, on Android 9, if the user didn't disable Chrome browser, the default WebView provider is the Chrome apk, they need to make sure they have updated Chrome to the right version.

I didn't see any report for any particular devices for the same printing issue after the fix. I don't have this device at hand, so if you can reproduce the issue, please file a WebView bug so we may request our testing team to verify the bug and then investigate more.

Manish Raje

unread,
Oct 23, 2020, 2:25:18 AM10/23/20
to android-webview-dev, Shimi Zhang, android-webview-dev, to...@chromium.org, Maunik Shah, Manish Raje
Hi Shimi,

Thanks for the input. Updating Google Chrome did the trick. Printing is working fine now.

Thank you very much. 
Manish.
Reply all
Reply to author
Forward
0 new messages