pramodkr123 / ConvertWebViewToPdfDemo

Convert WebView to pdf in android
MIT License
40 stars 19 forks source link

Is there a possibility to set Printmargins to 0? #5

Open KsgFellow opened 5 years ago

KsgFellow commented 5 years ago

Hello, I'd like to print a webview to pdf with a colored banner touching the edges. Looks good in Webview, but once printed to pdf it gets margins all around.

Is there any way to set these printmargins to 0 ?

Thanks in advance, Any help would be greatly appreciated.

pramodkr123 commented 5 years ago

PrintAttributes attributes = new PrintAttributes.Builder() .setMediaSize(PrintAttributes.MediaSize.ISO_A4) .setResolution(new PrintAttributes.Resolution("pdf", "pdf", 600, 600)) .setMinMargins(PrintAttributes.Margins.NO_MARGINS).build();

//change the height and width according to your requirement. .setResolution(new PrintAttributes.Resolution("pdf", "pdf", 600, 600))

//set margins .setMinMargins(PrintAttributes.Margins.NO_MARGINS)

Hope It will help you.

Let me know if you are getting any issue.

KsgFellow commented 5 years ago

Thanks for the response, but I have trouble figuring out were I'm supposed to put these PrintAttributes.

I have this: PdfView.createWebPrintJob(printWebView_Activity.this, webView, directory, fileName, new PdfView.Callback() { ..... } I havent been able to find a parameter I could fill with the attributes. (Or am I missing something?)