PDF Surfaces

PDF Surfaces — Rendering PDF documents

Functions

Types and Values

Object Hierarchy


Description

The PDF surface is used to render cairo graphics to Adobe PDF files and is a multi-page vector surface backend.

The following mime types are supported: CAIRO_MIME_TYPE_JPEG, CAIRO_MIME_TYPE_JP2, CAIRO_MIME_TYPE_UNIQUE_ID, CAIRO_MIME_TYPE_JBIG2, CAIRO_MIME_TYPE_JBIG2_GLOBAL, CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID.

JBIG2 data in PDF must be in the embedded format as described in ISO/IEC 11544. Image specific JBIG2 data must be in CAIRO_MIME_TYPE_JBIG2. Any global segments in the JBIG2 data (segments with page association field set to 0) must be in CAIRO_MIME_TYPE_JBIG2_GLOBAL. The global data may be shared by multiple images. All images sharing the same global data must set CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID to a unique identifer. At least one of the images must provide the global data using CAIRO_MIME_TYPE_JBIG2_GLOBAL. The global data will only be embedded once but shared by all JBIG2 images with the same CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID.

Functions

cairo_pdf_surface_create ()

cairo_surface_t *
cairo_pdf_surface_create (const char *filename,
                          double width_in_points,
                          double height_in_points);

Creates a PDF surface of the specified size in points to be written to filename .

Parameters

filename

a filename for the PDF output (must be writable), NULL may be used to specify no output. This will generate a PDF surface that may be queried and used as a source, without generating a temporary file.

 

width_in_points

width of the surface, in points (1 point == 1/72.0 inch)

 

height_in_points

height of the surface, in points (1 point == 1/72.0 inch)

 

Returns

a pointer to the newly created surface. The caller owns the surface and should call cairo_surface_destroy() when done with it.

This function always returns a valid pointer, but it will return a pointer to a "nil" surface if an error such as out of memory occurs. You can use cairo_surface_status() to check for this.

Since 1.2


cairo_pdf_surface_create_for_stream ()

cairo_surface_t *
cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func,
                                     void *closure,
                                     double width_in_points,
                                     double height_in_points);

Creates a PDF surface of the specified size in points to be written incrementally to the stream represented by write_func and closure .

Parameters

write_func

a cairo_write_func_t to accept the output data, may be NULL to indicate a no-op write_func . With a no-op write_func , the surface may be queried or used as a source without generating any temporary files.

 

closure

the closure argument for write_func

 

width_in_points

width of the surface, in points (1 point == 1/72.0 inch)

 

height_in_points

height of the surface, in points (1 point == 1/72.0 inch)

 

Returns

a pointer to the newly created surface. The caller owns the surface and should call cairo_surface_destroy() when done with it.

This function always returns a valid pointer, but it will return a pointer to a "nil" surface if an error such as out of memory occurs. You can use cairo_surface_status() to check for this.

Since 1.2


cairo_pdf_surface_restrict_to_version ()

void
cairo_pdf_surface_restrict_to_version (cairo_surface_t *surface,
                                       cairo_pdf_version_t version);

Restricts the generated PDF file to version . See cairo_pdf_get_versions() for a list of available version values that can be used here.

This function should only be called before any drawing operations have been performed on the given surface. The simplest way to do this is to call this function immediately after creating the surface.

Parameters

surface

a PDF cairo_surface_t

 

version

PDF version

 

Since 1.10


cairo_pdf_get_versions ()

void
cairo_pdf_get_versions (cairo_pdf_version_t const **versions,
                        int *num_versions);

Used to retrieve the list of supported versions. See cairo_pdf_surface_restrict_to_version().

Parameters

versions

supported version list

 

num_versions

list length

 

Since 1.10


cairo_pdf_version_to_string ()

const char *
cairo_pdf_version_to_string (cairo_pdf_version_t version);

Get the string representation of the given version id. This function will return NULL if version isn't valid. See cairo_pdf_get_versions() for a way to get the list of valid version ids.

Parameters

version

a version id

 

Returns

the string associated to given version.

Since 1.10


cairo_pdf_surface_set_size ()

void
cairo_pdf_surface_set_size (cairo_surface_t *surface,
                            double width_in_points,
                            double height_in_points);

Changes the size of a PDF surface for the current (and subsequent) pages.

This function should only be called before any drawing operations have been performed on the current page. The simplest way to do this is to call this function immediately after creating the surface or immediately after completing a page with either cairo_show_page() or cairo_copy_page().

Parameters

surface

a PDF cairo_surface_t

 

width_in_points

new surface width, in points (1 point == 1/72.0 inch)

 

height_in_points

new surface height, in points (1 point == 1/72.0 inch)

 

Since 1.2

Types and Values

CAIRO_HAS_PDF_SURFACE

#define CAIRO_HAS_PDF_SURFACE 1

Defined if the PDF surface backend is available. This macro can be used to conditionally compile backend-specific code.

Since 1.2


enum cairo_pdf_version_t

cairo_pdf_version_t is used to describe the version number of the PDF specification that a generated PDF file will conform to.

Members

CAIRO_PDF_VERSION_1_4

The version 1.4 of the PDF specification. (Since 1.10)

 

CAIRO_PDF_VERSION_1_5

The version 1.5 of the PDF specification. (Since 1.10)

 

Since 1.10

See Also

cairo_surface_t