[cairo] PDF backend: PDF trailer not written?

Sascha Steinbiss steinbiss at zbh.uni-hamburg.de
Mon Dec 1 10:54:37 PST 2008


Hi everyone,

I have a piece of software here (genometools.org bioinformatics library) 
which uses cairo as a backend to draw maps of genome annotations to PNG, 
PDF or PS files. One of the interfaces I added gets only a reference to 
a cairo_t and does its drawing operations on it, never touching the 
surface. I used this interface in a C program to draw multiple diagrams 
on a multi-page PDF surface by drawing one beneath the other (always 
passing in the same cairo_t), calling cairo_show_page() every time 
before the page height would be exceeded.

When playing around with this setup, however, in some cases the 
resulting PDF file gets truncated and therefore corrupted as the PDF 
trailer is seemingly not written (see attached file):

$ evince trailer.pdf
Error: PDF file is damaged - attempting to reconstruct xref table...
Error: Couldn't find trailer dictionary
Error: Couldn't read xref table
Error: PDF file is damaged - attempting to reconstruct xref table...
Error: Couldn't find trailer dictionary
Error: Couldn't read xref table

I tried inserting cairo_surface_flush() into the calling code at various 
points and ensured writing by calling cairo_surface_finish() just before 
destroying the surface, but no success. Files output by the PS backend 
seem to be fine. Some input cases also work well in both PDF and PS 
output. I also tried using the pdf for_stream surface constructor to 
write the output to a dynamic buffer, but it remains truncated there as 
well.

I tested the same code on an older machine (using cairo 1.2.4) and 
everything works fine there (though it is by orders of magnitude slower 
and the PDF output is uncompressed).

My question is now: is it basically possible to corrupt PDF output, 
especially  getting the PDF trailer dict omitted, only by drawing 
operations on a cairo_t without ever doing nasty things with the 
surface? If so, I would be glad to get some directions on how to ensure 
the PDF is complete. If this may be a bug, I can give more extensive 
code examples (although I cannot provide a minimal example without 
dependencies to my code at the moment, as I do not see the most likely 
cause yet). System is Linux, Arch to be exact.

Thanks in advance,
Sascha
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trailer.pdf
Type: application/pdf
Size: 27563 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20081201/f99765ee/attachment-0001.pdf 


More information about the cairo mailing list