I went through the internet to get the best option for PDF generation, of-course I am a big fan of Crystal Reports for PDF generation not only for its simplicity but also for its quality. But the problem with Crystal Reports is that it should be installed on your hosting server to work with your website. After going through many articles on the internet, I was able to generate an invoice as I expected. Background I will start with the requirements. To use itextSharp, you need to download the iTextSharp library as it is available for free. You can download it from here.

Author:Fenriktilar Gusida
Language:English (Spanish)
Published (Last):11 May 2008
PDF File Size:3.52 Mb
ePub File Size:19.73 Mb
Price:Free* [*Free Regsitration Required]

GetInstance pdfDoc, msReport ; pdfWriter. Checking Header Footer", new Font Font. Add para ; pdfDoc. CreateFont BaseFont. CP, BaseFont.

PdfWriter writer, iTextSharp. OnEndPage writer, document ; iTextSharp. Font iTextSharp. BeginText ; cb. SetFontAndSize bf, 12 ; cb. SetTextMatrix document. GetRight , document. GetTop 45 ; cb. ShowText text ; cb. AddTemplate headerTemplate, document.

GetBottom 30 ; cb. GetWidthPoint text, 12 ; cb. AddTemplate footerTemplate, document. AddCell pdfCell1 ; pdfTab. AddCell pdfCell2 ; pdfTab. AddCell pdfCell3 ; pdfTab. AddCell pdfCell4 ; pdfTab.

AddCell pdfCell5 ; pdfTab. AddCell pdfCell6 ; pdfTab. AddCell pdfCell7 ; pdfTab. Width - 80f; pdfTab. WriteSelectedRows 0, -1, 40, document. Height - 30, writer. MoveTo 40, document. Height - ; cb. LineTo document. Width - 40, document. GetBottom 50 ; cb. OnCloseDocument writer, document ; headerTemplate. BeginText ; headerTemplate. SetFontAndSize bf, 12 ; headerTemplate.

SetTextMatrix 0, 0 ; headerTemplate. ShowText writer. PageNumber - 1. ToString ; headerTemplate. EndText ; footerTemplate. BeginText ; footerTemplate. SetFontAndSize bf, 12 ; footerTemplate. SetTextMatrix 0, 0 ; footerTemplate. ToString ; footerTemplate. It will generate sample PDF that will look like below: I hope it helps!


Add Header and Footer in PDF Using iText in Java

At the bottom of the page we can optionally include a copyright symbol followed by some text. In the bottom right corner you can find the current page number, followed by the total number of pages. In this tutorial we demonstrate how to add a header and footer in a PDF document using iText. By extending from this class and overriding these methods, we can write additional data to the PDF document when these events occur.

EN ISO 9692-2 PDF

Subscribe to RSS


Related Articles