openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

Can not convert a html with <b></b> to bold font in the pdf

Open tszzzyeung opened this issue 8 years ago • 8 comments

<td class="flttblbodyB" colspan="3" style="padding-top:3px;"><font class="flt_date"> 02 Jul</font> - Please verify flight times prior to departure</td>&#13;
<td class="flttblhdrB" style="padding-top:3px;"><b>AIRLINE RES CODE</b> : </td>&#13;

Amendment :

builder.useFont(new File(System.getenv("SystemRoot")+"/fonts/" + "arialuni.ttf"), "Arial Unicode MS", 400, PdfRendererBuilder.FontStyle.NORMAL, true);

builder.useFont(new File(System.getenv("SystemRoot")+"/fonts/" + "arialuni.ttf"), "Arial Unicode MS", 700, PdfRendererBuilder.FontStyle.NORMAL, true);
builder.useFont(new File(System.getenv("SystemRoot")+"/fonts/" + "cour.ttf"), "Courier New", 400, PdfRendererBuilder.FontStyle.NORMAL, true);
builder.useFont(new File(System.getenv("SystemRoot")+"/fonts/" + "courbd.ttf"), "Courier New", 700, PdfRendererBuilder.FontStyle.NORMAL, true);

originally , my program added above lines , however i cannot get a desired result, but after i remove above lines , the pdf can display the normal style and bold style correctly, but my desired font is not set since i remove the above line. So my problem is, is there any way to set the font that i want and have a correct display of bold style.

tszzzyeung avatar Jun 21 '18 04:06 tszzzyeung

Did you try to set a breakpoint in PdfBoxFontResolver.resolveFont() and debugging this?

rototor avatar Jun 21 '18 15:06 rototor

Hi @tszzzyeung

No, the project does not currently support emulating bold fonts. You need to provide a bold version of the font you want to use. It seems you are providing a bold font but it is the same font file as the normal weight.

danfickle avatar Jun 22 '18 05:06 danfickle

oh.... that's the problem. thx a lot @danfickle !

tszzzyeung avatar Jun 25 '18 02:06 tszzzyeung

but will you guys having enhancement on that? @danfickle

tszzzyeung avatar Jun 25 '18 02:06 tszzzyeung

@tszzzyeung I don't think so. This would be a feature that FontBox (part of PdfBox) needs to implement. It's relativ easy (and ugly) to make a font bold by stretching it and then drawing it as streched vector graphics. But you usually want to have the font used as font, so that the text remains selectable in the PDF and the PDF does not expolde (size wise). To have it bold in PDF you need a bold version of the font. Creating such a version of a font is out of scope for this project.

rototor avatar Jun 25 '18 06:06 rototor

I think there is support for italic & bold emulation in #143 It just needs manual merging. Would anyone like to provide a pr with just this done?

danfickle avatar Jun 30 '18 04:06 danfickle

@danfickle As I needed this feature, I've cherry-picked the commit in the PR #143 done by @backslash47 and done a PR :)

syjer avatar Jul 01 '18 12:07 syjer

RC-14 has been released, so think we can close this.

danfickle avatar Jul 07 '18 11:07 danfickle