form fill: appearance text ignores font encoding /Differences
Author: ftesCreated Sep 16, 2026Updated Sep 16, 2026
Labelsinvestigate
Example
A text field uses the standard Courier font (/Subtype /Type1) with a custom encoding that swaps A and B.
Input
/Encoding <<
/BaseEncoding /WinAnsiEncoding
/Differences [65 /B /A]
>>Actual output
Filling the field with pdfcpu v0.15.0 succeeds, but AB COMPANY displays as BA COMPBNY in most viewers.
data='{"forms":[{"textfield":[{"name":"project_company_name","value":"AB COMPANY"}]}]}'
printf '%s\n' "$data" > data.json
pdfcpu form fill -c disable input.pdf data.json output.pdfAcrobat 2026.002.21901
MacOs Preview 11.0 (1113.5.3)
Surprisingly, Preview generates the expected output even for the 'bad' output PDF. Maybe Preview generates its own appearance from the correct field value (/V) instead of displaying the saved appearance stream (/AP).
Poppler 26.02.0
Ghostscript 10.07.1
gs -q -dSAFER -dBATCH -dNOPAUSE -sDEVICE=txtwrite -dTextFormat=3 -sOutputFile=- output.pdfBA COMPBNYExpected output
The field should display AB COMPANY in all viewers.
Suspected cause
The stored /V correctly contains AB COMPANY, but the generated appearance stream writes:
(AB COMPANY) TjThe font maps byte 65 to glyph /B and byte 66 to /A. The appearance therefore displays the wrong letters.
With this font encoding, the appearance needs to contain:
(BA COMPBNY) TjReferences
Source: pdfcpu/pdfcpu