User Documentation
Author Guillaume Ayoub Date 2011-02-13 This document is a short description for installing and using CairoSVG.
CairoSVG is written in pure Python and only depends on . It is known to work with Python 2.6, 2.7, 3.2 and 3.3.
Linux and OS X users certainly have Python already installed. For Windows users, please install thanks to the adequate installer.
CairoSVG can use to parse the SVG file, and plus to apply CSS not included in thestyleattribute of the tags. If these packages are not available, CSS will only be supported in thestyleattributes.
Embedded raster images other than PNG are handled by .
CairoSVG can be freely downloaded on the . Just get the file and unzip it in a folder of your choice.
Here is the simple CairoSVG usage:
Usage: cairosvg.py filename [options]Options: -h, --help show this help message and exit -v, --version show version and exit -f FORMAT, --format=FORMAT output format -d DPI, --dpi=DPI ratio between 1in and 1px -o OUTPUT, --output=OUTPUT output filenameSupported output formats arepdf,psandpng(default ispdf). The default output is the standard output. If an output filename is given, the format is automatically chosen according to the extension.
Thedpioptions sets the ratio between pixels and real-life units such as millimeters and inches (as explained in the ).
Moreover, if-is used as filename, CairoSVG reads the SVG string from the standard input.
Here are some usage examples:
# Convert to pdf, write to standard outputcairosvg test.svg# Convert to png, write to standard outputcairosvg test.svg -f png# Convert to ps, write to test.pscairosvg test.svg -o test.ps# Convert an SVG string to pdf, write to standard outputecho " " \ | cairosvg -Thecairosvgmodule offers 4 functions:
- svg2pdf,
- svg2png,
- svg2ps, and
- svg2svg(!).
These functions expect one of these parameters:
- bytestring, a byte string containing SVG, or
- url, an URL or a filename, or
- file_obj, a file-like object.
If thewrite_toargument is provided (filename or file-like object), the output is written there. Otherwise, the function returns a byte string.