1 /* gcc `pkg-config --cflags --libs librsvg-2.0 cairo-pdf` -o svg2pdf svg2pdf.c
3 * Copyright © 2005 Red Hat, Inc.
4 * Copyright © 2006 Red Hat, Inc.
5 * Copyright © 2007 Red Hat, Inc.
7 * Permission to use, copy, modify, distribute, and sell this software
8 * and its documentation for any purpose is hereby granted without
9 * fee, provided that the above copyright notice appear in all copies
10 * and that both that copyright notice and this permission notice
11 * appear in supporting documentation, and that the name of
12 * Red Hat, Inc. not be used in advertising or publicity pertaining to
13 * distribution of the software without specific, written prior
14 * permission. Red Hat, Inc. makes no representations about the
15 * suitability of this software for any purpose. It is provided "as
16 * is" without express or implied warranty.
18 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
19 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
21 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
22 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
23 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
24 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 * Authors: Kristian Høgsberg <krh@redhat.com>
27 * Carl Worth <cworth@redhat.com>
28 * Behdad Esfahbod <besfahbo@redhat.com>
33 #include <librsvg/rsvg.h>
34 #include <librsvg/rsvg-cairo.h>
36 #include <cairo-pdf.h>
39 do { fprintf (stderr, "FAIL: %s\n", msg); exit (-1); } while (0)
41 #define PIXELS_PER_POINT 1
43 int main (int argc, char *argv[])
47 RsvgDimensionData dim;
49 const char *filename = argv[1];
50 const char *output_filename = argv[2];
51 cairo_surface_t *surface;
53 cairo_status_t status;
56 FAIL ("usage: svg2pdf input_file.svg output_file.pdf");
60 rsvg_set_default_dpi (72.0);
61 handle = rsvg_handle_new_from_file (filename, &error);
63 FAIL (error->message);
65 rsvg_handle_get_dimensions (handle, &dim);
69 surface = cairo_pdf_surface_create (output_filename, width, height);
70 cr = cairo_create (surface);
72 /* Clear background */
73 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
76 rsvg_handle_render_cairo (handle, cr);
78 status = cairo_status (cr);
80 FAIL (cairo_status_to_string (status));
83 cairo_surface_destroy (surface);