When you talk about certificates, I think of standard sheets that look the same for each certificate recipient, with the exception of:
- receiver name
- course followed by the receiver
- the date
If so, I would use any tool that allows you to create a fancy certificate (Acrobat, Open Office, Adobe InDesign, ...) and create a static form (sometimes called AcroForm) containing three fields: name, course, date.
Then I used iText to populate the fields as follows:
PdfReader reader = new PdfReader(pathToCertificateTemplate); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(pathToCertificate)); AcroFields form = stamper.getAcroFields(); form.setField("name", name); form.setField("course", course); form.setField("date", date); stamper.setFormFlattening(true); stamper.close(); reader.close();
Creating such a certificate from code is a "hard way"; creating such a certificate from XML is a "pain" (because XML is not suitable for defining a layout), creating a document from (HTML + CSS) is possible using iText XML Worker, but all these solutions have the disadvantage that it works hard to correctly position each element, so that everything is on one page, etc ....
It is much easier to maintain a fixed margin template. This way you only need to code the code once. If for some reason you want to move the fields to another place, you only need to change the template, you do not need to worry about messing around in the code, XML, HTML or CSS.
See http://www.manning.com/lowagie2/samplechapter6.pdf (section 6.3.5) for more details.
source share