#121·pdfcraft

[Bug] Attachment names extracted via /tools/extract-attachments/ are garbled (likely UTF-8 decoded as Latin-1/Windows-1252)

Author: Leon-ShawCreated Sep 23, 2026Updated Sep 24, 2026

Minimal Reproducible Example_with_attachments.pdf

Description

When using the /tools/extract-attachments/ tool to extract embedded files from a PDF, the extracted filenames appear garbled (e.g., showing as 程佑附件). However, when opening the same PDF with other PDF readers or tools, the original filenames display correctly in proper Chinese (e.g., 程佑附件).

This strongly looks like a character encoding issue where UTF-8 encoded bytes (or PDF Doc Encoding / UTF-16 strings) are being incorrectly decoded or interpreted as Latin-1 / Windows-1252.

Steps to Reproduce

  1. Go to /tools/extract-attachments/.

  2. Upload a PDF file that contains attachments with non-ASCII (e.g., Chinese) filenames.

  3. Extract the attachments.

  4. Observe the resulting filenames in the download list or the extracted files.

Expected Behavior

The extracted attachment filenames should preserve their original characters correctly (e.g., 程佑附件), matching what is embedded in the PDF metadata.

Actual Behavior

Filenames are corrupted into mojibake strings (e.g., 程佑附件).

ImageImage