react-pdf: Text copied from PDF is sometimes incorrect

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 12
  • Comments: 21 (2 by maintainers)

Most upvoted comments

If someone else is using google fonts I also managed to fix the fonts using fontforge with the following command

fontforge -lang=ff -c 'Open($1); Generate($2); Close();' xxx.ttf yyy.ttf

I think we can close this bug as there are some easy workarounds

In my case suspect is font file.

After downloading font from another source and import in OpenSource BirdFont free software and export and use in my website.

It’s working as expected. Hope it helps someone 😃

June 7th Edit: This is still not fully functioning, some letters are wrong.

I also tried the following other solutions:

  • Tried to export using FontSquirrel with different options to fix the font
  • Tried to fix the font using the Glyphs software
  • Tried downloading the latest original font from the author

@diegomura it would be nice to understand a bit more about what could be causing this issue as this it preventing our users to search in the PDF we are providing them.


I just found out about this issue today while copy-pasting some text on my PDF (also found this related issue https://github.com/diegomura/react-pdf/issues/1950 - not sure if its worth keeping these 2 issues open since they look the same)

Here is my fix if it can help anyone:

  • Installed FontLab (yeah I know it’s not free, unfortunately…)
  • Open my .ttf font (in my case I was having an issue with Gilroy)
  • Once the font is opened, select all characters using CTRL-A
  • From the menu:
    • Tools > Font Audit > Check Glyphs
    • Tools > Font Audit > Fix problems
    • File > Export Font As > my-file-name.ttf (the file size was about 2x the original file)
  • Use this new file in React-pdf and it works! 🎉

I’m not sure how React-pdf uses the fonts to generate PDFs but given that I use the same font for my website and it works fine, it does look like this issue is specific to React-pdf and hopefully will get fixed

I had the same problem and I solved it using the method mentioned in the comment above with ‘BirdFont’. However, it seems like there might be a way to solve it without modifying the font. Check out this https://github.com/Hopding/pdf-lib/issues/245.

Any progress on that ? 🙏

@LukaszMiskowiak and @jasiekkrk, There are other issues here like #629 that mention downloading the BirdFont software. I had the same issue using the Roboto font where fi was not working correctly. After purchasing the commercial Birdfont software for 4.99 USD, I was able to import the font, and export it with default settings and now works just fine.

This was fixed in #2408 / #2488. The test case in the REPL now works correctly. This issue can be closed.

Exporting SourceHanSans with BirdFont did not fix all my issues. Some text copies correctly, but many do not.

I also have the same issue with fonts like Inter.