Fill PDF AcroForms with PHP


Fill in existing PDF forms with PHP

Fill in a Reader Enabled document with the SetaPDF FormFiller

Normally PDF forms are not saveable in the free Adobe Reader (before version X/10). Adobe offers different services which enable hidden feature in Adobe Reader by passing special digital signatures to a document.

The SetaPDF-FormFiller component is able to handle such document if you take care about the following facts:

How to prepare a document for unicode usage

An easy way to support unicode values is simply done by delegating the rendering process of form fields to the reader application. This is done by setting a flag via the setNeedAppearances() method of the FormFiller instance. If the component sets this flag in a rights enabled document, the digital signature will get invalid, the document will lose the rights and the client will receive an annoying error message.

If we would prepare a document with this special flag before attaching the rights, Acrobat, for example, will remove this flag automatically before enabling the rights...

Finally the only solution to simulate the needed behaviour is a simple JavaScript which has to be included into the "Document JavaScripts"-part of the document before enabling the reader rights. It will force the fields to be rerendered by swapping a simple property back and forth:

var isDirty = this.dirty;
var nFields = this.numFields;
var t = app.thermometer;
t.duration = nFields;
for (var i = 0; i < nFields; i++) {
    var f = this.getField(this.getNthFieldName(i));
    try {
        var v = f.value;
        if (v == '')
        f.multiline = !f.multiline;
        f.multiline = !f.multiline;
        f.value = v;
    } catch(e) {}
    t.value = i;
this.dirty = isDirty;

Try it your own with the following demo script: