Pink Jazz
Pink Jazz

Reputation: 802

Printing PDF via Print Manager - Print Preview Doesn't Match Output

I am using the example here to print PDFs via the Android Printing Framework: How to Print PDF using Android 4.4 Printing framework

However, the print preview doesn't match the print output. In truth, the output is correct but the preview isn't. Is there any way to correct this?

EDIT: Google PDF Viewer apparently shows the preview correctly when attempting to print a PDF. Is there some unknown way to get the preview to display correctly in the print preview? There doesn't appear to be any solutions anywhere.

Upvotes: 2

Views: 2489

Answers (1)

VV W
VV W

Reputation: 169

My suggestion is that data what you want to print , load throgh the webview and Print that data using PrintManager using webview adapter

we have Printmanager https://developer.android.com/reference/android/print/PrintManager and print the data and this manager needs printadapter which will get from webview createPrintDocumentAdapter

PrintManager printManager = (PrintManager)getSystemService(Context.PRINT_SERVICE);
PrintDocumentAdapter printAdapter;
if(android.os.Build.VERSION.SDK_INT >= 21){
    printAdapter = webView.createPrintDocumentAdapter(jobName);
}else{
    printAdapter = webView.createPrintDocumentAdapter();
}
PrintAttributes.Builder builder = new PrintAttributes.Builder();
builder.setMinMargins(PrintAttributes.Margins.NO_MARGINS);
builder.setMediaSize(PrintAttributes.MediaSize.ISO_A4);
File filePdf = new File(pathAndJobName);
printManager.print(filePdf.getName(), printAdapter, builder.build());

thanks,

Upvotes: 1

Related Questions