## PDF Surfaces PDF Surfaces — Rendering PDF documents |

## Synopsis

    #define             CAIRO_HAS_PDF_SURFACE
    cairo_surface_t *   cairo_pdf_surface_create            (const char *filename,
                                                             double width_in_points,
                                                             double height_in_points);
    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);
    void                cairo_pdf_surface_restrict_to_version
                                                            (cairo_surface_t *surface,
                                                             cairo_pdf_version_t version);
    enum                cairo_pdf_version_t;
    void                cairo_pdf_get_versions              (cairo_pdf_version_t const **versions,
                                                             int *num_versions);
    const char *        cairo_pdf_version_to_string         (cairo_pdf_version_t version);
    void                cairo_pdf_surface_set_size          (cairo_surface_t *surface,
                                                             double width_in_points,
                                                             double height_in_points);

## Description

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

## Details

### 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

### 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`.

`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`.

`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.

`surface` : | a PDF cairo_surface_t
`version` : | PDF version

Since 1.10

### enum cairo_pdf_version_t

    typedef enum {
        CAIRO_PDF_VERSION_1_4,
        CAIRO_PDF_VERSION_1_5
    } 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.

`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

### 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()`.

`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.

`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()`.

`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

## See Also

cairo_surface_t