-
Notifications
You must be signed in to change notification settings - Fork 359
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
How to override font family for all the text in html in PdfRendererBuilder? #641
Comments
PdfRendererBuilder builder = new PdfRendererBuilder();
builder.useFont(YOUR_FONT_SUPPILER, FONT_NAME);
builder.useCacheStore(PdfRendererBuilder.CacheStore.PDF_FONT_METRICS, new FSDefaultCacheStore());
|
Thanks for the reply. I found another way to do this:
I will definitely try your suggestion as I don't like reflection-to-private at all. |
hi @asu2 , I think it would be a nice feature to have a customizable Font resolver (edit: for fallback). I'll have a look at what it would mean during the week end. If you can post your subclass here, it would be a nice start to see what we would need to change/modify. |
@syjer here you go ;-)
|
openhtmltopdf/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxFontResolver.java Lines 421 to 430 in d20825b
|
yeah, an easily-accessible fallback font is exactly what I'm looking for. Currently I'm using your 'css-injection' solution which works very well. Thanks! |
looks like exposing the possibility to provide a programmatic way to let the user select the fallback font is the most elegant way. You register all the fonts that you need as normal and in the builder you pass something like:
|
Including major refactor of PDF font resolver and working test.
I've opened PR #669. Feel free to have a look and comment. Trying to do a long overdue release tomorrow though. Will merge first. |
to avoid mega class in PdfBoxFontResolver.
This optimization was assumable designed to avoid the O(n) lookup of a font family variants. However when n is mostly 4 or under it is unneeded and complicates the code without good reason. Speaking of premature opts, also added a few performance tweaks to the matching process.
Add !important after CSS font |
Hi,
The problem we have is that the html source files are from different vendors/countries so it seems impossible to load all fonts they are using or will use. I'd like to know if there's a way to override font for all the text, regardless which font family is declared for them in CSS (but still keep font style and size if possible), so I can simply specify an unicode-friendly font for all html sources.
Thanks!
The text was updated successfully, but these errors were encountered: