After asking this question back in November, I've been very happy with ReportLab for all of my python pdf-generation needs.
在11月回答这个问题后,我对ReportLab非常满意我的所有python pdf生成需求。
However, it turns out that while ReportLab will use regular TrueType (TTF) fonts, it does not support OpenType (OTF) fonts.
但是,事实证明,虽然ReportLab将使用常规TrueType(TTF)字体,但它不支持OpenType(OTF)字体。
One of the current widgets I'm working on is going to need to use some OpenType fonts, and so sadly, ReportLab just removed itself from the running.
我正在处理的当前小部件之一将需要使用一些OpenType字体,所以遗憾的是,ReportLab刚刚从运行中删除了自己。
Can anyone recommend an OpenType-compatible PDF generator for Python?
任何人都可以为Python推荐一个兼容OpenType的PDF生成器吗?
It doesn't need to be fancy - I just need to be able to drop UTF-8 text onto a page.
它不需要花哨 - 我只需要能够将UTF-8文本放到页面上。
Update: OpenType fonts, roughtly, come in two flavors: TrueType-style and PostScript-style, based on how they store glyph outlines. ReportLab just supports the TypeType-style. On Windows, it turns out, you can tell the difference by the extension: TrueType and OpenType of the TrueType-style are .TTF, OpenType with the PostScript style are .OTF.
更新:OpenType字体,有两种风格:TrueType风格和PostScript风格,基于它们存储字形轮廓的方式。 ReportLab只支持TypeType样式。在Windows上,事实证明,您可以通过扩展来区分:TrueType样式的TrueType和OpenType是.TTF,PostScript样式的OpenType是.OTF。
So, my real question is, can anyone recommend a Python PDF generator that supports .otf fonts?
所以,我真正的问题是,有人可以推荐支持.otf字体的Python PDF生成器吗?
2 个解决方案
#1
That sort of depends... OpenType was intended to extend TrueType (and uses the general structure of TrueType internally) - so much so that some folks have reported success using OpenType fonts in reportlab; I suppose it all depends on whether or not there are any special OTF characteristics that your use of the font requires.
这取决于...... OpenType旨在扩展TrueType(并在内部使用TrueType的一般结构) - 以至于有些人在reportlab中使用OpenType字体报告成功;我想这一切都取决于你使用字体是否需要特殊的OTF特性。
In fact, some comments in the TTFontFile class source for reportlab mention OpenType by name, so it's probably worth a shot.
事实上,报告的TTFontFile类源中的一些注释提到OpenType的名称,所以它可能值得一试。
EDIT: The comments reference an error message that pretty much summarizes the case where reportlab can't support an OTF font. OTF fonts can store outline data in several formats (see the wikipedia link above). In this case, the font appears to be using the CFF format, for which reportlab specifically checks in its font parser, and which reportlab specifically rejects with the error message "postscript outlines are not supported".
编辑:注释引用一条错误消息,几乎总结了reportlab不支持OTF字体的情况。 OTF字体可以以多种格式存储大纲数据(请参阅上面的*链接)。在这种情况下,字体似乎使用CFF格式,reportlab专门检查其字体解析器,以及哪个reportlab明确拒绝错误消息“不支持postscript轮廓”。
That pretty much ends my font and PDF-generator expertise. Sorry! Looking forward to seeing any suggestions of alternatives.
这几乎结束了我的字体和PDF生成器专业知识。抱歉!期待看到任何替代方案的建议。
EDIT 2: Ok, looking at the docs for Django, I see they reference another full PDF api: pdflib. I have no direct experience with PDFlib, and it's not free (neither price nor license). I also find their docs annoying as I couldn't just see the English API without downloading the whole bloomin package (don't know if there's a free trial or what). I did look at the German docs, though, which ARE mysteriously available for free, separate downlod. My second-language-in-university german did allow me to discern that they claim support for unicode and 8-bit OpenType fonts with postscript outlines.
编辑2:好的,看看Django的文档,我看到他们引用了另一个完整的PDF api:pdflib。我没有使用PDFlib的直接经验,而且它不是免费的(既不是价格也不是许可证)。我也发现他们的文档很烦人,因为我不能在没有下载整个bloomin包的情况下看到英文API(不知道是否有免费试用版或者什么)。不过,我确实看过德国文档,这些文档神秘地免费提供,单独下载。我的第二语言大学德语确实让我发现他们声称支持带有postscript轮廓的unicode和8位OpenType字体。
Do I sound enthused about them? Nope :-) Hopefully someone who uses and loves them will correct me, as I repeat I have no first-hand experience with them. It may be an option if your budget allows and all else fails.
我对他们听起来很热情吗?不是:-)希望有人使用和爱他们会纠正我,因为我重申我没有他们的第一手经验。如果您的预算允许且所有其他方法都失败,则可能是一个选项。
#2
It would be nice if reportlab had native OTF support but all most people really need is a TrueType version of a particular OpenType font. I used this fontforge script to convert the font I needed to TrueType with perfect results.
如果reportlab具有本机OTF支持会很好,但是大多数人真正需要的是特定OpenType字体的TrueType版本。我使用这个fontforge脚本将我需要的字体转换为TrueType,并获得完美的结果。
From http://www.se.eecs.uni-kassel.de/~thm/OpenOffice.org/bugs.html :
来自http://www.se.eecs.uni-kassel.de/~thm/OpenOffice.org/bugs.html:
#!/usr/bin/fontforge
# Quick and dirty hack: converts a font to truetype (.ttf)
Print("Opening "+$1);
Open($1);
Print("Saving "+$1:r+".ttf");
Generate($1:r+".ttf");
Quit(0);
#1
That sort of depends... OpenType was intended to extend TrueType (and uses the general structure of TrueType internally) - so much so that some folks have reported success using OpenType fonts in reportlab; I suppose it all depends on whether or not there are any special OTF characteristics that your use of the font requires.
这取决于...... OpenType旨在扩展TrueType(并在内部使用TrueType的一般结构) - 以至于有些人在reportlab中使用OpenType字体报告成功;我想这一切都取决于你使用字体是否需要特殊的OTF特性。
In fact, some comments in the TTFontFile class source for reportlab mention OpenType by name, so it's probably worth a shot.
事实上,报告的TTFontFile类源中的一些注释提到OpenType的名称,所以它可能值得一试。
EDIT: The comments reference an error message that pretty much summarizes the case where reportlab can't support an OTF font. OTF fonts can store outline data in several formats (see the wikipedia link above). In this case, the font appears to be using the CFF format, for which reportlab specifically checks in its font parser, and which reportlab specifically rejects with the error message "postscript outlines are not supported".
编辑:注释引用一条错误消息,几乎总结了reportlab不支持OTF字体的情况。 OTF字体可以以多种格式存储大纲数据(请参阅上面的*链接)。在这种情况下,字体似乎使用CFF格式,reportlab专门检查其字体解析器,以及哪个reportlab明确拒绝错误消息“不支持postscript轮廓”。
That pretty much ends my font and PDF-generator expertise. Sorry! Looking forward to seeing any suggestions of alternatives.
这几乎结束了我的字体和PDF生成器专业知识。抱歉!期待看到任何替代方案的建议。
EDIT 2: Ok, looking at the docs for Django, I see they reference another full PDF api: pdflib. I have no direct experience with PDFlib, and it's not free (neither price nor license). I also find their docs annoying as I couldn't just see the English API without downloading the whole bloomin package (don't know if there's a free trial or what). I did look at the German docs, though, which ARE mysteriously available for free, separate downlod. My second-language-in-university german did allow me to discern that they claim support for unicode and 8-bit OpenType fonts with postscript outlines.
编辑2:好的,看看Django的文档,我看到他们引用了另一个完整的PDF api:pdflib。我没有使用PDFlib的直接经验,而且它不是免费的(既不是价格也不是许可证)。我也发现他们的文档很烦人,因为我不能在没有下载整个bloomin包的情况下看到英文API(不知道是否有免费试用版或者什么)。不过,我确实看过德国文档,这些文档神秘地免费提供,单独下载。我的第二语言大学德语确实让我发现他们声称支持带有postscript轮廓的unicode和8位OpenType字体。
Do I sound enthused about them? Nope :-) Hopefully someone who uses and loves them will correct me, as I repeat I have no first-hand experience with them. It may be an option if your budget allows and all else fails.
我对他们听起来很热情吗?不是:-)希望有人使用和爱他们会纠正我,因为我重申我没有他们的第一手经验。如果您的预算允许且所有其他方法都失败,则可能是一个选项。
#2
It would be nice if reportlab had native OTF support but all most people really need is a TrueType version of a particular OpenType font. I used this fontforge script to convert the font I needed to TrueType with perfect results.
如果reportlab具有本机OTF支持会很好,但是大多数人真正需要的是特定OpenType字体的TrueType版本。我使用这个fontforge脚本将我需要的字体转换为TrueType,并获得完美的结果。
From http://www.se.eecs.uni-kassel.de/~thm/OpenOffice.org/bugs.html :
来自http://www.se.eecs.uni-kassel.de/~thm/OpenOffice.org/bugs.html:
#!/usr/bin/fontforge
# Quick and dirty hack: converts a font to truetype (.ttf)
Print("Opening "+$1);
Open($1);
Print("Saving "+$1:r+".ttf");
Generate($1:r+".ttf");
Quit(0);