How to change document text encoding or specify encoding of rendered text #239
-
Hello, When i add that contains characters with diacritics, its not rendered properly or some of them are missing. Here is the sample code i use: HexaPDF::Document.open(TEMPLATE_PATH).tap do |doc|
page = doc.pages[0]
canvas = page.canvas(type: :overlay)
canvas.font('Helvetica', size: 10)
canvas.text('ěščřžýáíé', at: [0, 0])
doc.write('foo.pdf', optimize: true)
end When I try to use Any idea how to fix that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
So, the first error you get As you found out you can work around this by using the It also works with mupdf on Android. So my guess is that the viewer you are using on Android can't handle non-standard Type1 encodings. What you can try is using a TrueType font instead. This will also allow you to display much more characters. |
Beta Was this translation helpful? Give feedback.
-
Than you, using a TrueType font fixed this issue! |
Beta Was this translation helpful? Give feedback.
So, the first error you get
Type1 encoding has no codepoint for ecaron (HexaPDF::Error)
is expected since the default encoding used by HexaPDF (which is not related to any encoding used in an opened PDF) just doesn't contain that codepoint.As you found out you can work around this by using the
custom_encoding: true
option. When I reproduce this I get the following result (in various viewers like okular, evince and Adobe Reader)It also works with mupdf on Android. So my guess is that the viewer you are using on Android can't handle non-standard Type1 encodings.
What you can try is using a TrueType font instead. This will also allow you to display much more characters.