6

I was having some problem when trying to include header and footer in multiple pages of pdf file when trying to convert from webview into pdf. Here is how I formed the content to be displayed in 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();
 }

And I followed this guide to generate PDF from webview. It did managed to generate the PDF file. However, the header only appeared in the first page and the footer only appeared in the last page of PDF file. Any ideas how to include the header and footer across all pages in the PDF file?

Thanks!

QWERTY
  • 2,303
  • 9
  • 44
  • 85
  • hi @hyperfkcb the link you mentioned in your question, can we create multiple pages in pdf by using webview? can you help me to solve my problem https://stackoverflow.com/questions/54870164/convert-html-into-pdf-using-webview-can-not-created-multiple-pages – Rucha Bhatt Joshi Feb 28 '19 at 09:35
  • I aslo have the same problem. Have you find any solution yet? Can you please help me? Please – Danish Ansari Apr 08 '19 at 08:48

1 Answers1

0

I had the same problem.

My working solution:

  1. Generate Pdf from Webview
  2. Save this Pdf
  3. Reopen the Pdf with PdfBox GitHub - TomRoush/PdfBox
  4. Add Header and Footer (with addCenterText) PdfBox - How to Center...
  5. Save the extended Version