https://bugs.documentfoundation.org/show_bug.cgi?id=173877

            Bug ID: 173877
           Summary: ** PDF export: non-ASCII characters in AcroForm field
                    names are exported as escaped UTF-8 bytes (#C3#A9)
           Product: LibreOffice
           Version: 26.2.5.2 release
          Hardware: x86-64 (AMD64)
                OS: Linux (All)
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: LibreOffice
          Assignee: [email protected]
          Reporter: [email protected]

Description:
When exporting a Writer document containing a PDF form, non-ASCII characters in
a form field **name** are represented differently from the same characters in
the field **value**.

For this test, both the field name and its value are:

`Prénom`

After exporting the document to PDF, Python's `pypdf` library reports the field
name as:

`Pr#C3#A9nom`

while the field value is correctly returned as:

`Prénom`

`C3 A9` corresponds to the UTF-8 encoding of `é`.

The issue was initially observed with LibreOffice 24.2.7.2.

After removing that installation and installing LibreOffice 26.2.5.2, the issue
was tested again and is still reproducible.

Current version used for the reproduction:

LibreOffice 26.2.5.2
6d2b0d33fb0f5da53a12f98bed3e9973e56ff1f0

The exported PDF was inspected with pypdf 6.19.0 on Ubuntu 24.04.5 LTS.

**Steps to reproduce**

1. Open LibreOffice Writer.
2. Create a text form control.
3. Set the control/field name to `Prénom`.
4. Export the document to PDF with PDF form creation enabled.
5. Set the value of the PDF field to `Prénom` and save the PDF.
6. Inspect the AcroForm field with Python and `pypdf`.

**Python test**

```python id="nwk6y9"
from pypdf import PdfReader

reader = PdfReader("PDF problem export.pdf")
fields = reader.get_fields()

for name, field in fields.items():
    print("Name :", name)
    print("repr :", repr(name))
    print("type :", type(name))
    print("value:", field.get("/V"))
```

**Result**

```text id="n4i4cj"
Name : Pr#C3#A9nom
repr : 'Pr#C3#A9nom'
type : <class 'pypdf.generic._base.TextStringObject'>
value: Prénom
```

Thus, the non-ASCII character is affected in the **field name**, but not in the
**field value**.

Using the ASCII-only field name `Prenom` does not exhibit the problem.

**Expected result**

The exported AcroForm field name should be represented so that PDF software can
retrieve:

```text id="71jv9w"
Prénom
```

rather than:

```text id="9ofuzh"
Pr#C3#A9nom
```

**LibreOffice version**

```text id="12vjw6"
LibreOffice 26.2.5.2
6d2b0d33fb0f5da53a12f98bed3e9973e56ff1f0
```

The same behaviour was previously reproduced with:

```text id="jewbrm"
LibreOffice 24.2.7.2 420(Build:2)
```

**Operating system**

```text id="3w6mvo"
Ubuntu 24.04.5 LTS (Noble Numbat)
```

**Additional files**

A minimal Writer document (`.odt`) containing the form field and the resulting
exported PDF can be provided for reproduction.




------------------------------------------------------------
RAW SCREEN DUMPS :
------------------------------------------------------------
(.venv) ach@ach-ROG-Strix-G6:~/dev/fillablePDFs$ python3 readPdf.py 
Nom : Pr#C3#A9nom
repr: 'Pr#C3#A9nom'
type: <class 'pypdf.generic._base.TextStringObject'>
valeur: Prénom
----------
(.venv) ach@ach-ROG-Strix-G6:~/dev/fillablePDFs$ libreoffice --version
LibreOffice 26.2.5.2 6d2b0d33fb0f5da53a12f98bed3e9973e56ff1f0
----------
(.venv) ach@ach-ROG-Strix-G6:~/dev/fillablePDFs$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.5 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.5 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/";
SUPPORT_URL="https://help.ubuntu.com/";
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/";
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy";
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
(.venv) ach@ach-ROG-Strix-G6:~/dev/fillablePDFs$ 

---------
from pypdf import PdfReader

reader = PdfReader('PDF problem export.pdf')
fields = reader.get_fields()

for name, field in fields.items():
    print("Nom :", name)
    print("repr:", repr(name))
    print("type:", type(name))
    print("valeur:", field.get("/V"))

---------
(.venv) ach@ach-ROG-Strix-G6:~/dev/fillablePDFs$ python3 -c "import pypdf;
print(pypdf.__version__)"
6.19.0
(.venv) ach@ach-ROG-Strix-G6:~/dev/fillablePDFs$ 
---------

Steps to Reproduce:
1.
1. Open LibreOffice Writer.
2. Create a text form control.
3. Set the control/field name to `Prénom`.
4. Export the document to PDF with PDF form creation enabled.
5. Set the value of the PDF field to `Prénom` and save the PDF.
6. Inspect the AcroForm field with Python and `pypdf`.
2.
3.

Actual Results:
The format of the actual FIELD NAME was incorrect, but the CONTENT of the field
(with the same name) was correct.So the encoding of the name and the encoding
of the content are different. 

Expected Results:
The field name "Prénom" (=first name in French) should have been "Prénom" on
the PDF, not Pr#C3#A9nom :-)


Reproducible: Always


User Profile Reset: No

Additional Info:
...The analysis and the formatting of the bug report was done with ChatGPT, who
'audited' and completed my report :-)

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to