#1487·pdfcpu

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

pdf
/Encoding <<
  /BaseEncoding /WinAnsiEncoding
  /Differences [65 /B /A]
>>

input.pdf

Actual output

Filling the field with pdfcpu v0.15.0 succeeds, but AB COMPANY displays as BA COMPBNY in most viewers.

bash
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.pdf

output.pdf

Acrobat 2026.002.21901

Image

MacOs Preview 11.0 (1113.5.3)

Image

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

Image

Ghostscript 10.07.1

bash
gs -q -dSAFER -dBATCH -dNOPAUSE -sDEVICE=txtwrite -dTextFormat=3 -sOutputFile=- output.pdf
BA COMPBNY

Expected output

The field should display AB COMPANY in all viewers.

expected.pdf

Image

Suspected cause

The stored /V correctly contains AB COMPANY, but the generated appearance stream writes:

pdf
(AB COMPANY) Tj

The 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:

pdf
(BA COMPBNY) Tj

References