Problem/Motivation

The module bundles a very old version of PDF.js (1.x). This version has incomplete support for Type1 and WinAnsi-encoded fonts, which are commonly used in PDFs generated by word processors (Microsoft Word, LibreOffice, etc.).

As a result, glyphs for accented and special characters (e.g. É, È, «, etc.) are not rendered in the viewer — they appear as blank spaces or dots. The underlying text data is correct, as copy-pasting the content from the viewer produces the expected characters. The issue is purely a font rendering problem in the bundled PDF.js version.

  1. Upload a PDF generated from a word processor (Word, LibreOffice) that contains accented characters (e.g. É, È, À, «, »).
  2. Display the file using the PDF Reader field formatter.
  3. Observe that accented and special characters are not rendered (blank spaces appear instead).
  4. Select and copy the affected text: the correct characters are present in the clipboard, confirming the text data is intact.

Proposed resolution

Update the bundled PDF.js to version 2.x or later. Starting from version 2.x, PDF.js ships CMap support (cMapUrl / cMapPacked) which resolves font encoding issues for Type1 and WinAnsi fonts. The public API (pdfjsLib.getDocument()) remains compatible, limiting the scope of changes required in viewer.js.

As a shorter-term fix, passing cMapUrl and cMapPacked: true to the existing getDocument() call may partially address the issue without a full version upgrade.

Remaining tasks

  • Identify the minimum PDF.js version that resolves the font rendering issue.
  • Update the bundled pdf.js and viewer.js files accordingly.
  • Bundle the required CMap files or reference them from an appropriate URL.
  • Test rendering of PDFs with accented characters across major browsers.

UI changes

None expected. The viewer appearance should remain identical.

API changes

None for module consumers. Internal changes to how PDF.js is initialized (getDocument() options) may be required.

Data model changes

None.

CommentFileSizeAuthor
#4 after-patch.png73.6 KBmacsim
#4 before-patch.png77.34 KBmacsim

Issue fork pdf_reader-3624798

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

macsim created an issue. See original summary.

macsim’s picture

Assigned: Unassigned » macsim

Tried the "shorter term solution" but it didn't fix the problem.
Upgrading to pdfjs-dist@2.16.105 works fine.
Going to provide a MR soon

macsim’s picture

Assigned: macsim » Unassigned
Status: Active » Needs review
StatusFileSize
new77.34 KB
new73.6 KB

MR opened ; adding images before / after