【问题标题】:Android Java generate PDF file from webview with separate header and footerAndroid Java 从 webview 生成带有单独页眉和页脚的 PDF 文件
【发布时间】:2018-12-10 07:28:28
【问题描述】:

我在尝试从 webview 转换为 pdf 时尝试在 pdf 文件的多个页面中包含页眉和页脚时遇到了一些问题。这是我如何形成要在 webview 中显示的内容:

 public String toHtml() {
    StringBuilder htmlStr = new StringBuilder("");
    htmlStr.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=utf-8>");
    htmlStr.append("<title>").append("").append("</title>");
    htmlStr.append("</head>\n");
    htmlStr.append("<body>").append("").append("</body>");
    htmlStr.append("<footer>").append("").append("</footer>");
    htmlStr.append("</html>");
    return htmlStr.toString();
 }

我跟着this guide 从 webview 生成 PDF。它确实设法生成了 PDF 文件。但是,页眉只出现在 PDF 文件的第一页,页脚只出现在 PDF 文件的最后一页。任何想法如何在 PDF 文件的所有页面中包含页眉和页脚?

谢谢!

【问题讨论】:

  • hi @hyperfkcb 您在问题中提到的链接,我们可以使用 webview 在 pdf 中创建多个页面吗?你能帮我解决我的问题吗stackoverflow.com/questions/54870164/…
  • 我也有同样的问题。你找到解决办法了吗?你能帮我么?请

标签: java android pdf


【解决方案1】:

我遇到了同样的问题。

我的工作解决方案:

  1. 从 Webview 生成 Pdf
  2. 保存此 PDF
  3. 使用 PdfBox GitHub - TomRoush/PdfBox 重新打开 Pdf
  4. 添加页眉和页脚(使用 addCenterText)PdfBox - How to Center...
  5. 保存扩展版本

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-26
    • 2019-10-07
    • 1970-01-01
    • 2015-03-10
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 2012-03-10
    相关资源
    最近更新 更多