Can I convert an HTML form to a PDF?

Tags: pdfHtmlAcroFormforms

Similar questions were asked on Stack Overflow on Jan 14, '14 by sneha and on Dec 1, '16 by SUNIL KUMAR E.U

There is limited support for converting HTML forms to a PDF document. We currently only support text fields. If you have an HTML file with text fields that you want to convert to PDF, you also have to indicate whether you want the resulting PDF to be an interactive form.

Let's take a look at the form.html HTML file:

A simple HTML form
A simple HTML form

If we want to convert this HTML form to a PDF form (based on AcroForm technology), we need to mention this explicitly in the ConverterProperties. See the C07E10_HelloAcroForm example:

public void createPdf(String src, String dest) throws IOException {
    ConverterProperties properties = new ConverterProperties();
    properties.setCreateAcroForm(true);
    HtmlConverter.convertToPdf(new File(src), new File(dest), properties);
}

Because of the line properties.setCreateAcroForm(true), an interactive PDF form is created. We can manually change the text in the fields with the blue background:

A simple PDF form
A simple PDF form

If we don't change the ConverterProperties, as is the case in the C07E11_HelloFormFlattened example, we will get a "flat" PDF:

A flattened form
A flattened form

The content of the fields is there, but there is no interactivity in the file. The content of what once were HTML fields can't be changed in a PDF viewer.

Using interactive PDF forms for the purpose of manual data entry is somewhat outdated. When a form is to be filled out manually, HTML 5 is usually preferred. If there's a need for pdfHTML to have broader support for converting HTML to PDF, we can put this on the technical roadmap. So far, we haven't had any request that justifies the effort of further HTML form to AcroForm development.