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.
Related
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.
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
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.
I'm generating a docx file using Apache POI 3.13 and I stuck with headers/footers for first page.
I create XMPFParagraph[] without any problem. Next I create headers and footers like this (I've tried in different oreder):
policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, defaultHeader);
policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, defaultFooter);
policy.createHeader(XWPFHeaderFooterPolicy.FIRST, firstHeader);
policy.createFooter(XWPFHeaderFooterPolicy.FIRST, firstFooter);
Once I generate my docx file I could see my default header/footer on every page including first one. But if I select to use different header/footer for the first page - my first header and footer apperes correctly.
How could I make this happens automaticaly via code? And is there any appropriate documentation with examples about POI?
If you want to set a first page header in a section, you must enter a title page tag in section properties tag (w:sectPr). The title page tag can be empty, but it is necessary. In your case, you can add only 2 code lines:
CTSectPr sect = document.getDocument().getBody().getSectPr();
sect.addNewTitlePg();
`Best regards!
i want to add a page header and page footer to my generated pdf. I use xmlworker for convert my html content to pdf.
I want to add a page header and page footer in every page of generated pdf, i have problems to do this task. How can i do this?
You have to implement an HeaderFooter class for your document which implements itexts PdfPageEventHelper class.
Just take a look at this example.
You want to create a header on each page, so you will just need to override the onEndPage() method.
Adding a footer can be done with this methode aswell. You can do so by adding content to the directContentByte using coordinates for the pages bottom like this:
ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("test"),
rect.getRight()-35, rect.getBottom()-25, 0);