Why does pikepdf fill-in some PDF fields but not others on a PDF created with Acrobat DC

891 Views Asked by At

I have a PDF with form fields created with Acrobat DC by my customer. Using Python pikepdf I'm filling those fields programmatically. The strange issue is that some fields are filled, others not. I checked and double-checked with Acrobat DC: All fields have the exact same Text Field Properties, with the names obviously being unique. The Python code addresses the fields with their correct name. So I suspect that the problem might be related to the way my customer created the fields. Using Acrobat DC I deleted the offending fields and created brand new ones with the same Text Field Properties as the fields that show up as filled in -- to no avail.

Now I checked the pikepdf-generated PDF with Acrobat Reader, and all filled-in fields display their value, sigh! However, none of the Linux PDF viewers displays the content of the offending fields while displaying the content of some other fields. I tried Okular, Atril, the document viewer of XFCE4, and LibreOffice Draw. This seems to indicate that the issue on the Acrobat side of things. Any ideas?

2

There are 2 best solutions below

0
On

@joelgeraci : You are right, pikepdf doesn't generate appearance streams. The strange thing is that a viewer like the XFCE4 Document Viewer displays the filled-in values for some fields, but not for others. Here's part of a page dump generated by pikepdf:

<pikepdf.Dictionary(type_="/Page")({
  "/Annots": [ {
    "/DA": "/HeBo 14 Tf 0 g",
    "/F": 4,
    "/FT": "/Tx",
    "/Ff": 12582912,
    "/MK": {

    },
    "/P": <.get_object(785, 0)>,
    "/Q": 1,
    "/Rect": [ Decimal('134.783'), Decimal('432.837'), Decimal('205.463'), Decimal('458.588') ],
    "/StructParent": 201,
    "/Subtype": "/Widget",
    "/T": "Number_01",
    "/Type": "/Annot"
  }, {
    "/DA": "/HeBo 14 Tf 0 g",
    "/F": 4,
    "/FT": "/Tx",
    "/Ff": 12582912,
    "/MK": {

    },
    "/P": <.get_object(785, 0)>,
    "/Q": 1,
    "/Rect": [ Decimal('590.089'), Decimal('430.645'), Decimal('660.768'), Decimal('455.76') ],
    "/StructParent": 202,
    "/Subtype": "/Widget",
    "/T": "Units_01",
    "/Type": "/Annot"
  } ],
...
})>

While field "Number_01" is shown as filled-in, field "Units_01" is not, although both do not have an appearance stream. Yet other fields do have an appearance stream and the filled-in value is displayed too, although pikepdf can't update appearance streams. I'm also wondering why Acrobat DC creates appearance streams for some fields, but not for others.

0
On

Solution

I stupidly passed an INT to pikepdf when filling the fields; passing a string solved the problem. What is more: The Linux viewers do not require the 'NeedAppearances' flag to display the filled-in values, while Acrobat Reader does need this flag.