Custom Fonts Copy & Paste Error #357
-
Hi @gettalong, We recently switched to HexaPDF to support embedding XML files (PDF/A compliance), and most things are working great. However, we’ve run into an issue with custom fonts where copying text from the generated PDF results in unreadable / gibberish output. This doesn’t happen when using one of the 14 standard fonts (e.g., Helvetica, Times), and does not occur with the same custom fonts in PDFs generated by other tools. Here’s a summary of our setup: composer = HexaPDF::Composer.new(page_size: :A4, margin: [85, 32.5]) composer.document.config['font.map'] = { What I’ve already tried:
Despite this, any text using a custom font still results in mostly unreadable characters when copied from the PDF. Could this be related to how the Unicode CMap is being generated in HexaPDF? Thanks in advance 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 20 replies
-
Which version of HexaPDF are you using? If not the latest, could you try with the latest? Could you provide a minimal example script with all necessary resources so that I can reproduce the problem? |
Beta Was this translation helpful? Give feedback.
-
Interesting 🤔 When I save the PDF and open it in a browser, copy & paste works correctly. However, when I save the PDF to my desktop and open it using the default viewer on my Mac, the pasted text turns into gibberish. I get something like: I asked a few colleagues to test this as well, and we’re all experiencing the same behavior. |
Beta Was this translation helpful? Give feedback.
@Jonathan-Ganss Thanks for being patient!
I was running out of ideas to test and asked on StackOverflow (see https://stackoverflow.com/questions/79560847/problem-with-tounicode-map-only-on-macos-preview). Turns out that Apple Preview is the culprit.
With the information from the answer I was able to modify HexaPDF to create a file that still doesn't need escaping when serializing and works with macOS Preview: example.pdf. Could you please also test that file? Thanks!