Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can anyone recommend a Python PDF generator with OpenType (.OTF) support? [closed]

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?

like image 786
Electrons_Ahoy Avatar asked Feb 28 '23 17:02

Electrons_Ahoy


2 Answers

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.

like image 79
Jarret Hardie Avatar answered Apr 27 '23 02:04

Jarret Hardie


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);
like image 26
joeforker Avatar answered Apr 27 '23 02:04

joeforker