How to fill and flatten PDF forms ?

Interactive PDF forms are collections of fields for gathering information interactively from the user. The form fields are stored separately from the visual content.  In simple terms, each form field typically has a name, type and a value. Each field also typically also has a visual appearance.  If it does not have an appearance, it can be generated by PDF.

Common Use Cases

UniPDF has a comprehensive support for PDF forms.  Key use cases:

  • Create new forms on top of documents.  For example create a PDF from Word with blanks and then add an interactive form on top of it.
    • pdf_form_add.go shows how to add create and apply a new form to an existing PDF.
  • Get list of fields from a form and their values.  Relevant examples:
  • Fill in a form with values.
    • pdf_form_fill_json.go supports exporting form data as JSON as well filling form and outputting a flattened PDF.
    • pdf_form_fill_custom_font.go illustrates on how to use a custom font (simple TTF font and CJK font) when filling and flattening forms.
  • Flatten a form such that the content becomes part of the document and not editable.
    • pdf_form_fill_json.go supports exporting form data as JSON as well filling form and outputting a flattened PDF.
    • pdf_form_fill_fdf_merge.go illustates FDF merging - merging FDF form data (values) with a template PDF, producing a flattened output PDF (with appearances streams generated).