Add page header and footer to pdf using itext xmlworker - java

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);

Related

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.

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

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

Adding Header or Footer on every page using ITextRenderer from HTML

I'm creating an HTML report usgin freemarker, and i produce a PDF from that HTML using ITextRenderer.
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(html);
renderer.layout();
renderer.createPDF(baosPDF);
I have a table in that html, with a header that successfully shows on every page using css classes:
thead { display:table-header-group }
Is it possible to do the same trick for an arbitrary section of my document? (let say, a div) I'ld like to keep my html vanilla, and identify the "header" and "footer" i want to see on every page using css.
Is it possible, only with css?
Perhaps you should have a look at
http://developers.itextpdf.com/content/itext-7-examples/converting-html-pdf
It gives a few examples of converting html to pdf. Including loading an external stylesheet.

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