[cairo] Size of PDF with lots of images

Adrian Johnson ajohnson at redneon.com
Thu Jan 16 12:01:34 PST 2014

On 17/01/14 02:07, Oswaldo wrote:
> El 16/01/2014 4:44, Behdad Esfahbod escribió:
>> Back in 2007 Carl and I developed Slippy a GUADEC to do our cairo
>> slides.  I
>> have used it since for many presentations.  It's a pycairo-based tool
>> where
>> you express slides as Python functions.  It's very handy, specially if
>> you
>> want to use cairo drawing in your slides.
>> Back in the days, if I had a huge background image, it was replicated
>> in each
>> slide, so I was getting, like, 240MB PDFs for a simple presentation.
>> Fortunately that has long been fixed.
>> Now, for my GLyphy talk [2], the source images are 14MB [3], but the
>> generated
>> PDF [4] is 18MB.  Does anyone feel like taking a look?
>> [1] http://github.com/behdad/slippy
>> [2] https://vimeo.com/83732058
>> [3] https://github.com/behdad/slippy/tree/master/glyphy
>> [4] http://behdad.org/glyphy_slides.pdf
> Hello,
> I do not know if your problem is this:
> I also use pyCairo to generate PDFs and when I used the same image on
> multiple pages (logos, backgrounds, etc) the pdf file was too large
> because if i use the same image ten times the image was embedded ten
> times in the pdf file.
> I solved it creating an image cache surface object, then, before create
> a new image surface I search the cache and, if exists on it, I reuse the
> previous created surface. In this way image was embedded only once.

Or you could use cairo_surface_set_mime_data() with the
CAIRO_MIME_TYPE_UNIQUE_ID mime type to assign a unique identifier (eg
the image file name) to your images. Images with the same unique
identifier will only be embedded once.

> Regards.

More information about the cairo mailing list