danfickle / danfickle/openhtmltopdf
Strange text on pdf when a builder.useFont is used
- Dominant language
- Java
- Stars
- 2.2k
- Forks
- 423
- PR merge metrics
- No merged PRs in 30d
Description
Hi all!
I'm creating a pdf with a custom font but I see the texts like this:

Also, some characters like € appears like #.
Do you know why is this happening?
This is the java code:
```
public static void main(String[] args) throws IOException, URISyntaxException {
File f = new File(OUTPUT_PATH);
if (f.exists()) {
f.delete();
}
HtmlToPdf app = new HtmlToPdf();
String html = "\\htmlToPdf\\templates\\input.html";
String font = "\\htmlToPdf\\fonts\\Arial.ttf";
PdfRendererBuilder builder = new PdfRendererBuilder();
URI myUri = app.getFileFromResourceAsStream(html);
builder.withUri(myUri.toString());
builder.toStream(new FileOutputStream(OUTPUT_PATH));
builder.useFont(new File(app.getFileFromResourceAsStream(font).getPath()), "Arial");
builder.useFastMode();
builder.run();
}
```
Do you know why is this happening?
Thank you so much
Best regards
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the reported HtmlToPdf main method and the PdfRendererBuilder.useFont call, then inspect the referenced Arial.ttf font and input.html. Reproduce the PDF generation with builder.run() and investigate why custom-font glyphs are rendered incorrectly, including why € becomes #. Done means the generated PDF displays the expected text and special characters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100