79355438

Date: 2025-01-14 15:08:49
Score: 1.5
Natty:
Report link

Thanks @Hans and @mkl for your inputs, on which I edited my question and hope it's not off-topic anymore, and I'll answer the question myself:

Using Apache PDFBox, you can fill a form text field with a known fully qualified name like this:

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDField;
import org.apache.pdfbox.pdmodel.PDDocument;
import java.io.File;


public class FillForm
{
    public static void main(String[] args) throws IOException
    {
        String formTemplate = "emptyform.pdf";
        PDDocument pdfDocument = Loader.loadPDF(new File(formTemplate));
        PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
        PDField text1 = acroForm.getField("Text1");
        text1.setValue("A Text");
        pdfDocument.save("filledform.pdf");
        pdfDocument.close();
    }
}
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Hans
  • User mentioned (0): @mkl
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Michi