views:

430

answers:

2

After asking this question back in November, I've been very happy with ReportLab for all of my python pdf-generation needs.

However, it turns out that while ReportLab will use regular TrueType (TTF) fonts, it does not support OpenType (OTF) fonts.

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.

Can anyone recommend an OpenType-compatible PDF generator for Python?

It doesn't need to be fancy - I just need to be able to drop UTF-8 text onto a page.


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.

So, my real question is, can anyone recommend a Python PDF generator that supports .otf fonts?

+3  A: 

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.

Jarret Hardie
Well, that's what I thought, but every time I hand the system an OTF file it crashes on me. I suspect that the ones that are crashing are the ones that are Type1 under the hood?
Electrons_Ahoy
Specifically, I'm getting the "postscript outlines are not supported" error on every .otf file I try to use.
Electrons_Ahoy
re edit: Aha, I think we were reading the same sourcecode at the same time. :) I guess it's just my bad luck that every otf file I have here uses the CFF format for outlines. Bummer. Thanks, Jarret.
Electrons_Ahoy
LOL... very good question. I use reportlab a lot, so I'm rather invested in it. Hope there's an alternative out there.
Jarret Hardie
Same here - ReportLab has been spectacular for ; here's hoping someone knows a way to get it to work with OTF files.
Electrons_Ahoy
+1  A: 

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.

From 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);
joeforker
An interesting suggestion, and cross-platform, and in a BSD-style license. Good to know!
Jarret Hardie