Android Java generate PDF file from webview with separate header and footer - java

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!

I had the same problem.
My working solution:
Generate Pdf from Webview
Save this Pdf
Reopen the Pdf with PdfBox GitHub - TomRoush/PdfBox
Add Header and Footer (with addCenterText) PdfBox - How to Center...
Save the extended Version

Related

iTextPDF 7 - Table of content with clickable page numbers

I'm trying to create a table of content with iTextPDF 7 in Java from existing PDFs.
I've tried to use Link link = new Link() and PdfAction.createGoTo(PdfExplicitDestination.createFit(pageNum)) but to no avail.
I can't link the page number/row in TOC to the respective page in the end PDF (after merging).
The documentation on their website only gets me so far and I'm out of ideas.
What is the correct way to create a TOC for existing PDFs and how to implement it correctly?

Setting footer in first page of a pdf file using dynamic reports

I am using java 8 and dynamic reports 6.0.0. I am generating a pdf file. I have to set the footer only in the first page.
There is a default method for setting the footer only in last page named lastPageFooter().
Code for adding footer in last page :
JasperReportBuilder report = new JasperReportBuilder();
report.lastPageFooter(cmp.text("footer text"));
Similarly I want to apply footer only for the first page. Please let me know how it can be one. Thanks in advance.

PDF is getting change after loading using PDFBOX jar

I have a PDF having first page as different page ( as we have in MS word functionality under "Design" tab ). and the same PDF is passed to PDFBOX using below code :
File originalPdfFile = new File("D:\\AsposeOutput_temp.pdf");
PDDocument originalDocument = PDDocument.load(originalPdfFile);
originalDocument.save("D:\\pdfBoxGen.pdf");
But when i am opening the PDF that is generated by PDFBOX, is modified. I have attached the input PDF (named AsposeOutput_temp.pdf) and output PDF (named : pdfBoxGen.pdf). I want the PDF to same as i am passing as input.
File links : https://gofile.io/?c=lLPpQz
Any help would be greatly appreciated!!
I got the solution for the above problem. There was no issue with PDFBOX library. it was with the Aspose word.The input file that was passed to PDFBOX library , was having section break internally and the same was making the improper alignment of footer.

How to add page header with some information and footer with page number in .docx file using docx4j with Java?

I have a word document with .docx extension. I want add header with some information and footer with page number in each page.
I don not know how add header and footer on word document.
I am using Docx4j open source edition with Java.
Start by looking at samples/HeaderFooterCreate.java
Basically you create the header and footer parts, and add them as rels of the MainDocumentPart. Then you reference these rels appropriately from the sectPr element.
For the actual content of your header/footer parts, I'd suggest you create a docx containing what you want in Word, then use the docx4j webapp or Helper AddIn to generate corresponding code.

IText html header/footer and table overlapping

I developed a method that converts a HTML file into a .pdf file, but this HTML file contains a repeated footer and header in each page.
The problem is that the content contains a big table that when this table getting bigger it overrides the footer and the header of the next page..
Here is an example PDF.

Categories

Resources