pdflib GetDocumentPageText returns incorrect text for PDF with embedded Unicode fonts

When using the GetDocumentPageText I get a lot of gibberish when the pdf contains embedded unicode fonts. The pdf is an existing pdf created by Adobe Indesign.

The extracted text looks like:

v./26.'#$A'e'#$A'O%%'#$A'GG v./26.'#$A'Fo '#$A'O%%'#$A'GG v./26.'#$A'O%%'#$A'GG v./26.'#$A'a'#$A'e'#$A'ks'#$A',g'#$A'O'#$A'// v./26.....

While the text in the pdf is extracted correct using pdfium or pdftotext

Result of pdffonts:

name type emb sub uni prob object ID


JFNELQ+StagSans-Medium Type 1C yes yes yes 1264 0
SDBBHY+ChunkFive-Roman Type 1C yes yes yes 1266 0
SDBBHY+Poppins-Black TrueType yes yes yes 1268 0
YVGZUM+StagSans-Book Type 1C yes yes yes 1273 0
KRAFZO+StagSans-Light Type 1C yes yes yes 322 0
YVGZUM+StagSans-Book Type 1C yes yes yes 329 0
QNAPFC+Arial-Black TrueType yes yes yes 331 0
...

link to file:

embedded fonts pdf

Hi Erwin,

Thank you for the report and for sending the PDF.

The PDF was created by InDesign, which writes the Unicode mapping of its embedded fonts with a 2-byte code range, even though these fonts use 1-byte character codes. Our text extraction used that code range for the fonts, so it combined every two characters into one, which produced the gibberish you saw.

This is fixed in TMS FNC Core: the character code size now follows the font type, as defined in the PDF specification.

The fix will be included in the next TMS FNC Core update.

Hi Pieter,

Thanks for the quick solution.

The text is coming through, that is very nice to see.

One detail, sometimes the text has no space where there should be. I tested this with the document with this result (just the first page):

Promotie geldig van 18/06 t.e.m. 24/06/2026.
Grillhesp
PROMO33%
KORTING

The 33% should be separated from the PROMO with a space like:

Promotie geldig van 18/06 t.e.m. 24/06/2026.
Grillhesp
PROMO 33%
KORTING

Best regards,

Erwin

Hi,

We are currently uploading a new version that should address this. Thanks for reporting!