2

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.

Pink Jazz
  • 784
  • 4
  • 13
  • 34
  • Which print service are you using. In reality the pdf that is handed to the print service is the same used to create the preview, but the print service could use a different pdf renderer to create the output where as the print framework uses PDFium: https://opensource.google.com/projects/pdfium, so you may need to file a bug against it – Nonos May 14 '18 at 17:21
  • I'm using the Canon Print Service. – Pink Jazz May 14 '18 at 17:48
  • UPDATE - In Google PDF Viewer the preview shows correctly. – Pink Jazz May 14 '18 at 19:03
  • Post some pictures of how the pdf differs – Niza Siwale May 23 '18 at 15:48

1 Answers1

1

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,

VV W
  • 169
  • 7