Has it ever happened to you that you fill out a PDF form and when you sended to someone else, that person has received an empty form? I will teach you one way to fix these errors by using pdftk (CLI) or PDF Chain (GUI).

Table of Contents

pdftk

pdftk (PDF Toolkit) is a great PDF tool (see Encrypting PDFs) and one thing it can do is extracting text from a form and re-add it as a plain text (removing the form inputs).

Script below takes two arguments: the input and output file. It will create a temporary file (inside working directory) with the form info. You can delete the file after the process if you want. After extracting the form inputs, it will fill out the PDF again but it will “flatten” it, i.e. it will convert the form inputs to plain text.

#!/bin/bash
# ./flat-forms

INPUT=$1
OUTPUT=$2
TEMPFILE=`basename -s .pdf $INPUT`.fdf

pdftk $INPUT generate_fdf output $TEMPFILE
pdftk $INPUT fill_form $TEMPFILE output $OUTPUT flatten
./flat-forms input.pdf output.pdf

PDF Chain

PDF Chain is a graphical frontend for PDFtk, available in Flatpak, and you can flatten a file with just a few clicks. Open PDF Chain and go to “Tools” tab. Select a PDF in the “Document” section and check “Document flatten”. Finally, click “Save As” to save the new flattened file.

Test with this online terminal: