Can I convert an HTML form to a PDF?
There is limited support for converting HTML forms to a PDF document. 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:
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
(Java/.NET). See the C07E10_HelloAcroForm (Java/.NET) 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);
}
public void CreatePdf(String src, String dest)
{
ConverterProperties properties = new ConverterProperties();
properties.SetCreateAcroForm(true);
HtmlConverter.ConvertToPdf(new FileStream(src, FileMode.Open, FileAccess.Read),
new FileStream(dest, FileMode.Create, FileAccess.Write), properties);
}
Because of the line properties.setCreateAcroForm(true)/ properties.SetCreateAcroForm(true), an interactive PDF form is created. We can manually change the text in the fields with the blue background:
If we don't change the ConverterProperties
(Java/.NET), as is the case in the C07E11_HelloFormFlattened (Java/.NET) example, we will get a "flat" PDF:
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.