XML To Fillable PDF Form?

11,715

Addendum (see comment): I'm the CEO of the iText Software Group, the original developer of iText (an open source PDF library), and the author of two 'iText in Action' books published by Manning. I'm a member of the NBN, which is the Belgian Office for Standards (including ISO-32000 and related PDF standards). I'm not affiliated with Adobe, Open Office, etc...

There are two "flavors" of forms in PDF: AcroForm-based and XFA forms.

In AcroForm-based forms, the form is described using PDF syntax, and every field has fixed coordinates. Think of it as digital paper. If you have a form representing an invoice, then such a form could provide 20 invoice lines. Suppose that you need less lines, you'll have a number of unused fields that will remain visible. Suppose that you need more lines, you won't be able to fit them all into the form. I have described how to create such a form using Open Office in chapter 6 of my book (see section 6.3.5). The only link with XML is that you can import/export such a form in the XFDF format, which is a spec that is referred to in ISO-32000-1. It's the XML version of the Forms Data Format (FDF). This could be ideal if you want to store people's responses on a server in the form of XML. You can test this here. Fill out the form and choose the XFDF button. The servlet that receives your request will return the stream that was sent to the server by Adobe Reader.

It might also be interesting to take a look at the XML Forms Architecture (XFA). In this case, the PDF acts as a container for an XML stream. The embedded XML consists of different parts of which the template and the datasets are the most important. In the template, specific syntax is used to define what the form should look like (how it has to be rendered by Adobe Reader). The datasets part consists of the dataDescription, which resembles XSD, and the data. One of the major benefits of XFA, is that the data consists of XML that uses whichever schema you want. XFA forms are typically created using Adobe LiveCycle Designer in which you import your own XSD as a data source, and then you can start designing your form. The result will be an empty template. Filling the form is as easy as injecting your XML into the data tag.

Which type of form is best for you?

AcroForms are always static. If your form needs to be an exact match of an existing form on paper, this is your best match. If you need forms that can grow dynamically (much like HTML), you'll soon get frustrated with AcroForms, although there are workarounds that seem to work perfectly.

XML Forms can be very dynamic. See for instance a form for movies. It consists of only one page. Now let's inject an XML file with 120 movies. The result is a form with 23 pages. As you can see, the fields for one movie are repeated 120 times. The field with the director and the country where the movie is produced can also be repeated if necessary. One major downside is that forms like this can only be rendered in Adobe Reader; they don't show up in Apple's Preview and many other non-Adobe PDF viewers.

I'm not sure if this answer helps you out. If not, please clarify as you seem to focus on details such as checkboxes.

Addendum:

Aha, reading your question a second time, I now see that I misunderstood the question. You don't want to create XML output after filling out a form. You want to create a form based on XML input (the point of view regarding input/output in your question is confusing).

So: you're not using Open Office, Adobe Acrobat or Adobe LiveCycle Designer to create the form. You want to convert your own custom XML into an interactive PDF. I don't know of any software that allows you to create an XFA form based on an XML except maybe the Adobe LiveCycle ES. If AcroForms are acceptable, then you need to write a parser for your custom XML and use a PDF library to create the form. Such a PDF library could be iText (maybe in combination with a custom implementation of XML Worker), but note that this will demand some extra programming.

There is no "out-of-the-box" solution to automatically convert custom XML into an interactive PDF form.

Share:
11,715

Related videos on Youtube

munkee
Author by

munkee

Updated on August 15, 2022

Comments

  • munkee
    munkee over 1 year

    I would like to create a fillable PDF form via an xml document?

    We currently have a database with line items for a checklist which we then output in to an xml format. We can produce some nice HTML 5 checklists but we are now moving towards PDF Forms.

    I have done some searches already but there is nothing really definitive out there to create PDF's from XML. We want to be able to define which fields are required, dropdowns, textboxes, etc.

    How can I create a PDF fillable form given an XML document?

  • Ilya Evdokimov
    Ilya Evdokimov over 8 years
    Thank you for the background information - this was useful to me.