Reputation: 65
The fonts associated with any text inside PDF files are embedded to PDF file causing the file size to increase considerably.
Is it possible to remove all those embedded fonts from a PDF file to reduce the file size? Instead, I want to use fonts from the local machine or from a specific location. Can I achieve this with either Compart DBMill or PDFLib or Perl?
Rasterizing the text is not an option since it would make the text inaccessible.
Upvotes: 2
Views: 5017
Reputation: 54371
It looks like CAM::PDF can do that. It has a deEmbedFont method that removes references to a font, and the documentation says you should use cleanse
afterwards to gain a size benefit.
Removes embedded font data, leaving font reference intact. Returns true if the font exists and 1) font is not embedded or 2) embedded data was successfully discarded. Returns false if the font does not exist, or the embedded data could not be discarded.
The optional $basefont parameter allows you to change the font. This is useful when some applications embed a standard font (see below) and give it a funny name, like SYLXNP+Helvetica. In this example, it's important to change the basename back to the standard Helvetica when de-embedding.
De-embedding the font does NOT remove it from the PDF document, it just removes references to it. To get a size reduction by throwing away unused font data, you should use the following code sometime after this method.
$self->cleanse();
Upvotes: 3