java - Android Java 从 webview 生成带有单独页眉和页脚的 PDF 文件
问题描述
尝试从 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();
}
我按照本指南从 webview 生成 PDF。它确实设法生成了 PDF 文件。但是,页眉只出现在 PDF 文件的第一页,页脚只出现在 PDF 文件的最后一页。任何想法如何在 PDF 文件的所有页面中包含页眉和页脚?
谢谢!
解决方案
我有同样的问题。
我的工作解决方案:
- 从 Webview 生成 Pdf
- 保存此 PDF
- 使用 PdfBox GitHub 重新打开 Pdf - TomRoush/PdfBox
- 添加页眉和页脚(使用 addCenterText)PdfBox - 如何居中...
- 保存扩展版本
推荐阅读
- jinja2 - 有没有办法删除 jinja2 for 循环中的空行?
- java - 为什么 java.net.URI 不解析权限部分?
- azure - 在 Azure Devops 中,如何让一些贡献者在没有项目管理员的情况下创建 sprint?
- java - Intellij 在 Gradle 中无法识别我的 Java 应用程序?
- python - 当某人已经获胜时如何终止井字游戏(使用 Tkinter)
- c++ - 非公共类型的公共别名
- sql - 执行 postgres 查询
- java - 由于BackgroundFallback initVivoBgFallback,数据未插入服务器
- c - 在 main 中获取 __attribute__ ((constructor)) 函数的值
- python - 使用pytest测试一个使用请求库的函数