[cairo] writing multiple surfaces to a single (pdf) file

Kalle Vahlman kalle.vahlman at gmail.com
Mon Nov 7 00:27:46 PST 2011

2011/11/7 Zoltán Vörös <zvoros at gmail.com>

> Well, this is/was actually the problem: I did read the docs, but it is
> completely unclear to me what one is supposed to do. At the moment, I have
> this
>            surface = cairo.PDFSurface('pdffile.pdf'**, 504, 648);
>            cr = cairo.Context(surface)
>            cr.set_source_surface(self.**surface, 0, 0)
>            cr.paint()
>            self.page += 1
>            self.path = self.pages[self.page]                     # we show
> another page
>            self.draw_note(self.widget('**draw'), self.path)   # This
> redraws the surface on gtk drawable, which is self.surface
>            cr.set_source_surface(self.**surface, 0, 0)
>            cr.copy_page()
>            cr.show_page()
> and it does print two pages to the pdf file, but the two pages are the
> same. I can't get the second page to the file, though it is painted
> properly on the self.surface, so I can it in the gui.

I have zero experience with using this API, but to me it looks like you are
doing to the context:

1. paint the page 1 from self.surface
2. set source surface to self.surface (now containing page 2)
3. copy the current page (which I guess would be page 1 since nothing is
telling otherwise), possibly including an implicit show_page()?
4. show(create?) the (copy of?) next page

So at no point is the page 2 painted to the context as far as I understand
it. You should probably be calling show_page() after paint() of 1st page,
and do the same after paint()ing the 2nd page, and not call copy_page() at

> Well, any hints would be appreciated.

I hope my guesses are correct rather than just confusing :)

Kalle Vahlman, zuh at iki.fi
Powered by http://movial.com
Interesting stuff at http://sandbox.movial.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20111107/29110d59/attachment-0001.html>

More information about the cairo mailing list