[cairo] Multiple pages in single PDF ?

Behdad Esfahbod behdad at behdad.org
Tue Sep 2 14:14:05 PDT 2008

Ian Britten wrote:
> Behdad Esfahbod wrote:
>> rush ta wrote:
>>> >From the documentation i understand that it is poosible to read from
>>> muliple pages and copy them to a surface..
>>> Is it possible to create multiple pages in a single PDF file.
>>> I am trying to print a table into PDF file. The content of which may
>>> be exceed to 2 pages.
>>> Currently i am making another PDF file for storing the exceded data.
>>> But its a lame solution i guess... Any help please... ?
>> cairo_show_page()
> [ I'm assuming you meant cairo_surface_show_page() ... ]

Both exist and both work.  One on a cairo_t, the other on a cairo_surface_t.

> Interesting - This got me thinking about something similar, since
> this topic came up...
> We often produce large sized output (eg: Desk-sized maps).  Our
> rendering mechanism simply renders one 'page', and the user prints
> it to their plotter (or printer, etc), which is expected to be big
> enough to handle it.
> Can any of this Cairo functionality be used so as to cut up a
> PDF surface after it's been generated?  Sortof like some final
> processing stage, after all the rendering has been done to a single
> PDF Surface, but before it's written out to disk?  I really don't
> want to have to rework our drawing engine right now to be aware of
> multiple pages, but it'd be nice if a large plot could be cut into
> smaller pages.  A common use of this is to send the printout to a
> cheaper/faster printer, for rough QA, etc.
> Yes, I'm aware of fact that separate post-processing tools can
> do this sort of work, but they require separate installation and
> use (And training!) by the end-user.  I'm just wondering if the
> same functionality can be achieved from within the Cairo API.

You can do this with cairo, but you are quite likely to get a HUGE output
file.  Like the entire drawing operations repeated for each page.  If still
interested, here is how you do it:

  - Create your final PDF surface with the target paper size, call it pdf.

  - Create a surface "similar" to your pdf surface, the size of the map.  Use
cairo_surface_create_similar(), call it similar.

  - Draw the map to the similar surface.

  - Then for each desired page in the final pdf:

    Use cairo_set_source_surface() with the similar surface.  Use the
    offset argument to position the map in the page.

    If desired, add a clip rectangle to introduce margins.



Hope that helps,


> Thanks for any information!
> Ian

More information about the cairo mailing list