Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.6k stars 635 forks source link

How to use Chinese characters #1566

Open KuiDaXElaina opened 7 months ago

KuiDaXElaina commented 7 months ago

What were you trying to do?

I've encountered issues handling traditional Chinese PDF files while using PDFlib.

How did you attempt to do it?

When I drag a PDF file containing traditional Chinese into PDF-lib, the webpage displays an error, and the PDF file cannot be processed as expected. image

What actually happened?

I even tried to use ttf to directly load the entire glyph into js (Embed Font and Measure Text), but whenever the browser wanted to load ttf, it would pop up in violation of CORS regulations, but the magic is that using the official website (PDF- The ttf link provided by lib) does not violate the CORS regulations, but it still cannot be used. The ttf does not support Chinese. I have tried for a whole week, but I still haven’t solved the problem of PDF-lib processing Chinese.

And I found that PDF files processed with ttf have become fatter, from 9xKB to 13XX KB, which is too big.

What did you expect to happen?

Is there any chance for PDF lib to directly support Chinese processing? Whether it’s Traditional Chinese or Simplified Chinese

How can we reproduce the issue?

image 你好呀.pdf

Version

1.17.1

What environment are you running pdf-lib in?

Other

Checklist

Additional Notes

No response

AmilKey commented 6 months ago

have a look at README https://github.com/Hopding/pdf-lib/tree/master?tab=readme-ov-file#fonts-and-unicode