danfickle / danfickle/openhtmltopdf

Cyrillic symbols

Open
#820 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.2k
Forks
423
PR merge metrics
No merged PRs in 30d

Description

Hi! I have a problem displaying Cyrillic symbols. I have an HTML containing Cyrillic symbols. The problem is that after converting they all displaying like "###" instead of symbols. I'm using the library like this:
```
var document = Jsoup.parse(new ByteArrayInputStream(resultHtml), "UTF-8", "/");
ByteArrayOutputStream os = new ByteArrayOutputStream();
try (os) {
var temp = new W3CDom().fromJsoup(document);
PdfRendererBuilder builder = new PdfRendererBuilder();
builder.toStream(os);
builder.useFont(new File("/resources/fonts/times.ttf"), "Times");
builder.withW3cDocument(temp, null);
builder.run();
}
return os;
```
The `resultHtml` is a HTML string and it's okay, because using another library (let's not say the name) I got the result I wanted: I got PDF with normal symbols, I'm saying it only to cut the area of possible problems, so I assume the problem is how I use the library. I don't really have any resources related to html, that's why it's `baseUri` is `/` and `null`. Library gives me 2 warnings but I don't think the problem is because of that because it says it's ignoring it.
```
com.openhtmltopdf.css-parse WARNING:: (null#inline_style_1) so-language is an unrecognized CSS property at line 21. Ignoring declaration.
com.openhtmltopdf.css-parse WARNING:: (null#inline_style_1) so-language is an unrecognized CSS property at line 32. Ignoring declaration.
```
I checked in the debug, I can see the `document` is okay because I can see the formed HTML with cyrillic symbols normally, but the `temp` is becoming `[#document:null]`. I read that it doesn't mean the document is null, but maybe it's the problem? I tried different charsets like `CP1251`, `CP1252` but they're giving strange symbols too. At first I tried all charsets without the font declaration, because the only font in use is ```TimesNewRoman``` and I think it's default, but then added it in `resources` and in code declaration, but it didn't help. I'm using `1.0.10` version of library and `1.14.3` version of `jsoup`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.