【发布时间】:2018-03-22 16:21:07
【问题描述】:
我尝试使用 Flying Saucer 为以下 HTML 生成 PDF:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 300;
src:url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAGSwABMAAAAAtfwAAQAAAAA...zubbzBiN9B2+6bK8AAAABV9JwXgAA) format('woff');
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: Identity-H;
}
body {
font-family: Roboto;
font-size: 26px;
font-weight: 300;
letter-spacing: -.03em;
}
</style>
</head>
<body>
<p>The quick brown fox jumps over the lazy dog</p>
</body>
</html>
base64 字体取自https://gist.github.com/abelaska/9c9eda70d31315f27a564be2ee490cf4
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(data);
renderer.layout();
renderer.createPDF(os);
当我从 Adobe Reader 检查属性中使用的字体时,列出的是 Times New Roman 而不是上面的字体。
如果我在 css 中使用字体的路径,PDF 会正确显示字体。
src:url(/usr/local/Roboto.woff)
有人可以告诉我我缺少什么,或者这是飞碟限制吗?
【问题讨论】:
标签: pdf itext flying-saucer