I use my own TrueType PDF font created using the xhtmlrenderer flying saucer.
ITextRenderer renderer = new ITextRenderer(); renderer.getFontResolver().addFont("myfont.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); renderer.setDocument(XMLResource.load(in).getDocument(), url); renderer.layout(); renderer.createPDF(out);
and inside the displayed html I have the following (for example)
<html> <head> <style type="text/css"> *{font-family:myfont;} </style> </head> <body> <p>some plain text<b>some bold text</b> <span style="font-weight:bold;">more bold</span></p> </body> </html>
but even with <b> and font-weight:bold I can’t get the text in bold.
Now I know that this should work, because I have a similar (inherited) project that uses the same font, and a plain old itext (i.e. no xhtmlrenderer), and it creates pdf files with bold text via:
myFont = BaseFont.createFont("myfont.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); Font boldFont = new Font(myFont); boldFont.setStyle(Font.BOLD); com.lowagie.text.Document document = ...; document.add(new Paragraph("plain", myFont)); document.add(new Paragraph("bold", boldFont));
can someone explain why i can't use bold with xhtmlrenderer and maybe a way to overcome this problem?
thanks p.
source share