I am looking for a way to create PDF (no need for digital certificates for now). What is the easiest and convenient way of doing that? I have tried
- XSL to PDF conversion
- HTML to PDF conversion using itext.
- the crude Java way (using
What is the best way out of these, or is there any other way which is easier and convenient?
When you talk about Certificates, I think of standard sheets that look identical for every receiver of the certificate, except for:
- the name of the receiver,
- the course that was followed by the receiver,
- a date.
If this is the case, I would use any tool that allows you to create a fancy certificate (Acrobat, Open Office, Adobe InDesign,...) and create a static form (sometimes referred to as an AcroForm) containing three fields:
I would then use iText7 to fill in the fields like this:
PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(new FileOutputStream(dest))); Document doc = new Document(pdfDoc); PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, false); Map fields = form.getFormFields(); fields.get("name").setValue(name); fields.get("course").setValue(course); fields.get("date").setValue(date); form.flattenFields(); doc.close();
Creating such a certificate from code is "the hard way"; creating such a certificate from XML is "a pain" (because XML isn't well-suited for defining a layout), creating a certificate from (HTML + CSS) is possible with iText's XML Worker, but all of these solutions have the disadvantage that it's hard work to position every item correctly, to make sure everything fits on the same page, etc...
It's much easier to maintain a template with fixed fields. This way, you only have to code once. If for some reason you want to move the fields to another place, you only have to change the template, you don't have to worry about messing around in code, XML, HTML or CSS.
Please go to the section about interactive forms to learn more about this technology.
Click How to create a complex PDF document? if you want to see how to answer this question in iText 5.