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!

2
  • 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 stackoverflow.com/questions/54870164/… Feb 28, 2019 at 9:35
  • I aslo have the same problem. Have you find any solution yet? Can you please help me? Please Apr 8, 2019 at 8:48

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.