[reportlab-users] [PATCH] Add TTF Embedding Option
yroman-reportlab at altalang.com
Thu Oct 16 18:38:14 EDT 2008
NOTE: I'm resending this since the list appears to have bounced it
because of the attached PDFs.
I've obviously offended the PDF gods by even suggesting this :-). To
respond to everyone's questions...
> my earlier suspicions are proved correct. Using more than the first
> subset causes an error
> There may be some way to use unicode as the output format, but I don't
> know enough about how adobe reader works with these non-embedded
> system fonts to answer for sure. I don't think we should let this
> patch go till we can get at least this primitive test to work.
I ran similar tests with Acrobat, and it's doing more behind the scenes
than it lets on. It switches to embedded subsets, regardless of the
"Never Embed" list, if any non-CP1252 characters are used and for
certain CP1252 characters. The latter seems to kick in at the 181 range
but not for all 181 to 255 code points.
I took another stab at my patch and got your test to pass. The trick was
to return CP1252 codes in splitString instead of UTF-8 and to re-enable
embedding if a CP1252 conversion wasn't possible. I also had to change
addObjects to include the widths of all CP1252 characters used in a
single subset, re-enable embedding if there was more than one subset,
and specify the WinAnsiEncoding when not embedding.
What I didn't like about it, though, is that, if the CP1252 conversion
failed halfway through, there was no way to cleanly handle it. I could
keep embedding info in the TTFont but there would be no way to go back
and revert those CP1252 code points to UTF-8 code points.
So I'm retracting my patch; it was an interesting exercise :-).
> can you explain why you cannot follow the earlier recommendation to
> use the built-in fonts (Helvetica, ...) instead?
That's what I'll end up doing. I assume the only effect that would have
is with Mac users that did have Arial.
> Are you using compression when you create your PDFs? That makes a big
> difference in size.
I am. The difference is still pretty large, though. Examples attached
[stripped]. Acrobat-Arial.pdf [43KB] and ReportLab-Arial.pdf [129KB] are
the "same" document using all four variants of Arial, embedded. I'm on
Acrobat 9 but had it generate a 1.3 PDF. ReportLab-Arial-Small.pdf
[45KB] was with setting asciiReadable to 0; it's much smaller although
I'm not sure I understand all the implications.
More information about the reportlab-users