Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom font #20

Closed
aleksandr-m opened this issue Apr 15, 2016 · 4 comments
Closed

Use custom font #20

aleksandr-m opened this issue Apr 15, 2016 · 4 comments

Comments

@aleksandr-m
Copy link

aleksandr-m commented Apr 15, 2016

Any way to use custom font? There is PdfBoxFontResolver, but currently don't see how to add custom font to it.

@danfickle
Copy link
Owner

danfickle commented Apr 16, 2016

Currently, the easiest way is to use a font-face rule in your css. Note: Only truetype fonts are supported and this will not currently work in the Java2D renderer - see #17

@font-face {
    font-family: "Noto Sans";
    src: url("NotoSans-Regular.ttf"); /* Use an absolute or relative url. */
}

/* Later, use font as named: */
body {
    font-family: 'Noto Sans', sans-serif;
}

If you want to add it in code instead, let me know and I'll give you a code sample.

@aleksandr-m
Copy link
Author

The thing is I need to load font from the jar. I can get PdfBoxFontResolver from PdfBoxRenderer but currently addFont method loads font with FileInputStream. Can you add another addFont method which loads resources from the classpath (e.g. with getResourceAsStream)?

danfickle added a commit that referenced this issue Apr 19, 2016
…put stream (such as from a resource).

Based on pull-request by @aleksandr-m Thanks a lot.
@danfickle
Copy link
Owner

I think the referenced commit does what you want. You can also use a jar url or a relative url if the document url is from a resource. Let me know if the provided method doesn't work. Thanks, Daniel.

@aleksandr-m
Copy link
Author

Initially I was thinking too about adding method with input stream but then noticed that there is check for .ttf and opted for TrueTypeFont.

Anyway, now it should work. Thanks.
I'm planing to upgrade struts2-pdfstream when you release next version with this improvement.

burka pushed a commit to burka/openhtmltopdf that referenced this issue Apr 26, 2024
* Change groupid to reflect the transition into organization

* Doing builds and especially releases both on push and PR leads into duplicate builds. We should choose on of them, and I think PR should suffice

* Release process (danfickle#21)

* The first commit in the repo is from 2004, so I find it correct to state that as the inception year

* Updated the Maven compiler plugin as well

* Updated the Maven source and javadocs plugins

* Minor tweaks

* First take on a release pipeline

* Getting there

* Switching to using semver instead

* Updated groupid to adhere with what Maven central expects and accepts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants