Webview in PDF ignores work title

I am trying to print an HTML page from a webview in KitKat (4.4.4), mainly using the sample code provided in the Google API documentation . Accordingly, I set the name of the print job as follows:

String jobName = getString(R.string.app_name) + " Document"; PrintJob printJob = printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build()); 

My code works fine and the page prints as intended. Even if the user selects the “save as PDF” option in the Android standard print dialog, the codes display a good PDF file and the user can select a file name. At this point, I expected Android to use the string stored in the jobName field as the file name. Instead, it always uses webview as the file name, although my code does not contain webview as a string.

Is there a way to set a different default name for storing a PDF file created in my application?

Thanks for your tips ...

Update:

I spent some extra time investigating this problem, and I found that webview uses the AwPrintDocumentAdapter as a print adapter if the adapter was created by calling createPrintDocumentAdapter() , as suggested in the API documentation. This class then calls PrintDocumentInfo.Builder("webview") , which seems to be the reason that PDF is always called "webview". Some studies show the following code snippet in the AwPrintDocumentAdapter :

 @Override public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle metadata) { mAttributes = newAttributes; // TODO(sgurun) pass a meaningful string once b/10705082 is resolved PrintDocumentInfo documentInfo = new PrintDocumentInfo .Builder("webview") .build(); // TODO(sgurun) once componentization is done, do layout changes and // generate PDF here, set the page range information to documentinfo // and call onLayoutFinished with true/false depending on whether // layout actually changed. callback.onLayoutFinished(documentInfo, true); } 

Therefore, this, apparently, is the main cause of my problem - at least if this code got to my Nexus 4 test device ... Finally, the best way to deal with this name problem is to print the adapter normally.

Are there any other solutions that do not require a special print adapter (which should contain code for calculating the number of pages, etc.)?

+8
android printing pdf webview
source share

No one has answered this question yet.

See related questions:

1475
Convert HTML + CSS to PDF using PHP?
1115
Recommended way to embed PDF in HTML?
1111
Correct MIME Media Type for PDF Files
1002
Grid motion detection
830
Combining / converting multiple PDF files into one PDF file
17
Android 4.4 Print to PDF without user intervention
one
Change document name when printing using Ghost Script
0
Android Webview does not download PDF files
0
Printing a password-protected PDF file Using a byte array in PrintDocumentAdapter
0
Open several pages in webview and create a PDF file.

All Articles