4

在 11 月问这个问题后,我对 ReportLab 非常满意我所有的 python pdf 生成需求。

然而,事实证明,虽然 ReportLab 将使用常规 TrueType (TTF) 字体,但它不支持 OpenType (OTF) 字体。

我正在处理的当前小部件之一将需要使用一些 OpenType 字体,因此可悲的是,ReportLab 刚刚从运行中删除了自己。

任何人都可以为 Python 推荐一个兼容 OpenType 的 PDF 生成器吗?

它不需要花哨 - 我只需要能够将 UTF-8 文本放到页面上。


更新:OpenType 字体大致有两种风格:TrueType 风格和 PostScript 风格,这取决于它们存储字形轮廓的方式。ReportLab 只支持 TypeType 样式。事实证明,在 Windows 上,您可以通过扩展名区分:TrueType 样式的 TrueType 和 OpenType 是 .TTF,PostScript 样式的 OpenType 是 .OTF。

所以,我真正的问题是,谁能推荐一个支持 .otf 字体的 Python PDF 生成器?

4

2 回答 2

4

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.

In fact, some comments in the TTFontFile class source for reportlab mention OpenType by name, so it's probably worth a shot.


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".

That pretty much ends my font and PDF-generator expertise. Sorry! Looking forward to seeing any suggestions of alternatives.


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.

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.

于 2009-05-21T22:51:45.707 回答
4

如果 reportlab 有原生的 OTF 支持,那就太好了,但大多数人真正需要的是特定 OpenType 字体的 TrueType 版本。我使用这个 fontforge 脚本将我需要的字体转换为 TrueType 并获得了完美的结果。

来自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);
于 2009-05-21T23:27:48.537 回答