PDFBox 2.0 和 TTC 字体 [英] PDFBox 2.0 and TTC Fonts
问题描述
由于 TTC 支持的可用性,我正在尝试使用 PDFBox 2.0(20151009 的快照).但我还没有找到任何关于如何使用此功能的文档.我在这里找到了一张票 https://issues.apache.org/jira/browse/PDFBOX-2752,我找到了如何加载 TTC 文件:
I am trying to use PDFBox 2.0 (snapshot of 20151009) due to the availability of TTC support. But I haven't found any documentation on how to use this feature. I found a ticket here https://issues.apache.org/jira/browse/PDFBOX-2752 and I found how to load TTC file:
InputStream is = MyClass.class.getResourceAsStream("font.ttc");
TrueTypeCollection coll = new TrueTypeCollection(is);
但我不知道如何将 TrueTypeFont 嵌入到我的 PDDocument 中.在 PDFBox 1.8 中,我使用了类似于以下内容的内容:
but I don't know how to embed TrueTypeFont into my PDDocument. In PDFBox 1.8 I was using something similar to the following:
public String addFont(String key, PDFont font){
PDResources res = pdfForm.getDefaultResources();
if (res == null){
res = new PDResources();
}
String fontName = res.addFont(font);
pdfForm.setDefaultResources(res);
return fontName;
}
但我知道我有一个 TrueTypeFont 而不是 PDFont.如何将 TrueTypeFont 转换为 PDFont ?还是我用错了东西?
but know I have a TrueTypeFont not a PDFont. How can I "convert" a TrueTypeFont into PDFont ? Or am I using something in a wrong way ?
谢谢
推荐答案
这是全新的 (https://issues.apache.org/jira/browse/PDFBOX-3018),并将在即将发布的 2.0 版本中(但不在 RC1 中).这是 Windows 的示例代码:
This is brandnew (https://issues.apache.org/jira/browse/PDFBOX-3018), and will be in the upcoming 2.0 release (but not in RC1). Here's a sample code for windows:
PDFont font = PDType0Font.load(document, new TrueTypeCollection(new File("c:/windows/fonts/MSGothic.ttc")).getFontByName().get("MS-Gothic"), true);
这篇关于PDFBox 2.0 和 TTC 字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!