如何从android中的webview中删除页眉和页脚,默认情况下会添加?

时间:2017-10-11 19:50:28

标签: android html css pdf webview

我正在以编程方式将html代码加载到android的webview中,然后以编程方式从中制作pdf文件并保存到磁盘。我可以成功创建pdf,但添加了一些奇怪的页眉和页脚,因为我的pdf页面大小增加到2而不是1.我如何删除它。下面是图像。我已从图像中删除了实际数据,但您可以看到覆盖额外空间的页眉和页脚。这些页眉和页脚在下图中标记为红色。 enter image description here

生成pdf的代码: 第1部分:

               printWrapper.setHtmlContent(billDetails);
               //webView.setBackgroundColor(Color.GREEN);
               webView.loadDataWithBaseURL(null, printWrapper.getHtmlContent(), "text/HTML", "UTF-8", null);
               // Keep a reference to WebView object until you pass the PrintDocumentAdapter
               // to the PrintManager
               mWebView = webView;

第2部分:

String jobName = getString(R.string.app_name) + " Document";
        PrintAttributes attributes = new PrintAttributes.Builder()
                .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
                .setResolution(new PrintAttributes.Resolution("pdf", "pdf", 600, 600))
                .setMinMargins(PrintAttributes.Margins.NO_MARGINS).build();
        File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS + "/");
        PdfPrint pdfPrint = new PdfPrint(attributes);
        pdfPrint.print(webView.createPrintDocumentAdapter(jobName), path, "Invoice.pdf");

有人可以帮我解决这个问题吗?

0 个答案:

没有答案