pdf-lib icon indicating copy to clipboard operation
pdf-lib copied to clipboard

Is it possible to set the character set to UTF-8 or a locale (type "es-ES" for example) "?

Open patryn32 opened this issue 8 years ago • 6 comments

I just started doing tests with pdf-lib, and I'm wondering if you can set the character set to my locale (in this case 'es-ES') to be able to see all the characters correctly. My program fills in a pdf form, and it gets it without problems. Although with the exception of course of the Spanish characters. Here is my code. informevnpdflib.zip

patryn32 avatar Jul 20 '18 09:07 patryn32

Hello @patryn32. I'm afraid there is not currently a way to change the character set or locale. This is something that I'd definitely like to support, though. I've placed it on the TODO.md file.

I can't make any promises as to when I'll get around to implementing this. However, if non-english text is an absolute requirement for you, one (hacky) way to get it done would be to produce an image of the text (perhaps using node-canvas) and draw that image onto the PDF. You can find an example of drawing an image on a PDF in this example.

Hopding avatar Jul 23 '18 21:07 Hopding

Hi,

I can suggest to add Encoding 'WinAnsiEncoding' to the Font dictionary.

See https://github.com/jerp/pdf-lib/commit/199ecf2d67fa734f31f4caa332abe1a36460d8d1

Check out result in attached document (see "distribución") - I din't have the original doc, so I used the one in test-pdf directory

Jerome. InformeVN-user-20180828164746141.pdf

jerp avatar Aug 28 '18 14:08 jerp

Version 0.4.0 is now published. It contains support for the WinAnsi character set when using one of the Standard 14 Fonts (example). The full release notes are available here.

You can install this new version with npm:

npm install [email protected]

It's also available on unpkg:

@jerp Thanks for your contributions to this release!

Hopding avatar Oct 31 '18 00:10 Hopding

Version 0.6.0 is now published. It contains support for the full range of UTF-8 and UTF-16 characters included in embedded fonts (example). The full release notes are available here.

You can install this new version with npm:

npm install [email protected]

It's also available on unpkg:

Hopding avatar Dec 30 '18 03:12 Hopding

Hi, This may be a stupid question but, does It contains support for the full range of UTF-8 and UTF-16 characters included in embedded fonts mean I can use a custom font and print characters in said font just fine ? (I'm trying to print chinese characters)

shxdow avatar Apr 13 '20 16:04 shxdow

@shxdow That is correct. So long as the font you embed supports a particular character, you should be able to draw it on a PDF page with pdf-lib.

Hopding avatar Apr 17 '20 00:04 Hopding