java itextpdf 5.5.6自定义字体未正确显示
我正在使用ITextPdf(5.5.6)和我的java+android web应用程序生成pdf。我想用Gotham Light字体查看内容。因此,我下载了一个Gotham Light.ttf文件,并创建了如下字体。 在我生成的pdf中,它看起来是很好的字体,但更粗体 我使用的iText版本确实支持Gotham Ligh 我正在使用的代码:java itextpdf 5.5.6自定义字体未正确显示,java,fonts,itext,Java,Fonts,Itext,我正在使用ITextPdf(5.5.6)和我的java+android web应用程序生成pdf。我想用Gotham Light字体查看内容。因此,我下载了一个Gotham Light.ttf文件,并创建了如下字体。 在我生成的pdf中,它看起来是很好的字体,但更粗体 我使用的iText版本确实支持Gotham Ligh 我正在使用的代码: Template t = ve.getTemplate(contratXHTML, "UTF-8"); StringWriter write
Template t = ve.getTemplate(contratXHTML, "UTF-8");
StringWriter writer = new StringWriter();
t.merge(context, writer);
String body = writer.toString();
writer.close();
OutputStream os = new FileOutputStream(absolutePathContratPDF);
renderer.getFontResolver().addFont("C:\\Windows\\Fonts\\Gotham Light_0.ttf",BaseFont.EMBEDDED);
renderer.setDocumentFromString(body);
renderer.layout();
renderer.createPDF(os);
os.close();
FileUtils.deleteQuietly(new File(pathTemporalDirectory));
return body;
你能帮帮我吗?我遇到了类似的问题 问题不在于您添加的字体,而在于要以PDF格式打印的正文(HTML正文)所使用的CSS/样式 请正确指定字体系列。在我的例子中,我使用了Arial字体和 字体系列:Arial;在 我的字体与标签不匹配。 那么,把它改成 字体系列:无衬线 解决了这个问题 在少数情况下,您可能需要定义 字体系列:Arial、Helvetica、无衬线字体 参考: