Creating a subset of a font

56 views
Skip to first unread message

Federico Bernardi

unread,
Jan 15, 2010, 7:50:14 PM1/15/10
to dompdf
I want to help someone like me in subsetting a font, in order to build
smaller PDF files that embeds font.

My logo is a short string in Palatino Linotype Roman ("bbros") with
just 4 different chars, but Palatino font takes 300kb in my PDF files.
I've created a short map of that font simply cutting /usr/local/share/
ttf2pt1/maps/CP1250.map file into a new file, that I called logo.map
and it contains just the following four rows:

!62 U+0062 b
!6F U+006F o
!72 U+0072 r
!73 U+0073 s

Then I ran ttf2pt1 with the following paramters

ttf2pt1 -b -L logo.map pala.ttf

and I've obtained a compressed pala.pfb and I gained a smaller PDF of
about 300kb less.
I tried to do the same with the other fonts, used often in the
document (like Verdana), but I had more issues than other, so I decide
to do the subset only for the logo.
I feel like suggesting you to use always "ttf2pt1 -b" to earn same
byte.

BrianS

unread,
Jan 16, 2010, 10:42:06 PM1/16/10
to dompdf

This is definitely something I would like to do in the future. With so
many other problems to work out, though, this one will have to wait a
few releases until we have the time. We'll keep your post in mind,
though, so that we have a good starting point for working out what we
need to do in order to subset fonts. Thanks for looking into this and
sharing the information.
-b

Federico Bernardi

unread,
Feb 19, 2010, 10:32:57 AM2/19/10
to dompdf
Just for information, I noticed a mistake in one of my shell script.
I used ps2pdf (a conversion tool distributed in the ghostscript
package for linux) to convert a PDF file to a PostScript.
Yes, it was a mistake, I should had use pdf2ps. Anyway I obtained a
very very small file.
From 133kb to 19kb! and the file look the same, with clickable url,
fonts, etc.

Also I update my php scripts in this way:

$process = proc_open("/usr/bin/ps2pdf - -", array(0 => array("pipe",
"r"), 1 => array("pipe", "w"), 2 => array("file", "/tmp/error.log",
"a")), $pipes);
if ( is_resource($process) ) {
fwrite($pipes[0], $dompdf->output());
fclose($pipes[0]);
$pdf_output = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($process);
$output->stream($pdf_output);
}
else {
$pdf_output = $dompdf->output();
$dompdf->stream($filename, array('Attachment' => 0));
}

$repository->save_as($pdf_output, $filename);

$output and $repository are two my classes, they aren't dompdf object.
I put they there just for example.

:) Really nice small pdf! :)

The best way is to process the output in dompdf.cls.php, so you can
"stream" or "output" without add this patch all the times.
but.. where should I put it?? in each adapters?
Bye!

Federico

> -b- Nascondi testo citato
>
> - Mostra testo citato -

BrianS

unread,
Feb 19, 2010, 11:02:05 AM2/19/10
to dompdf

If I wanted to add this functionality inline with DOMPDF I would
consider adding a new method to the adapters. That way you can easily
use the new functionality while still having access to the original
methods.

Reply all
Reply to author
Forward
0 new messages