CairoSVG - Convert SVG to PNG or PDF - Contents
2014-01-04 19:23
567 查看
CairoSVG - Convert SVG to PNG or PDF - Contents
This document is a short description for installing and using CairoSVG.
Edit this pageInstallationDependencies
CairoSVG
Command-Line UsageDescription
Examples
API
Linux and OS X users certainly have Python already installed. For Windows users, please install Python thanks to the adequate installer.
CairoSVG can use lxml to parse the SVG file, and tinycss plus cssselect 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 Pillow.
Thedpioptions sets the ratio between pixels and real-life units such as millimeters and inches (as explained in the specification).
Moreover, if-is used as filename, CairoSVG reads the SVG string from the standard input.
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.
User Documentation
Author | Guillaume Ayoub |
---|---|
Date | 2011-02-13 |
Edit this pageInstallationDependencies
CairoSVG
Command-Line UsageDescription
Examples
API
Installation
Dependencies
CairoSVG is written in pure Python and only depends on Pycairo. 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 Python thanks to the adequate installer.
CairoSVG can use lxml to parse the SVG file, and tinycss plus cssselect 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 Pillow.
CairoSVG
CairoSVG can be freely downloaded on the project website, download section. Just get the file and unzip it in a folder of your choice.Command-Line Usage
Description
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 specification).
Moreover, if-is used as filename, CairoSVG reads the SVG string from the standard input.
Examples
Here are some usage examples:# Convert to pdf, write to standard output cairosvg test.svg # Convert to png, write to standard output cairosvg test.svg -f png # Convert to ps, write to test.ps cairosvg test.svg -o test.ps # Convert an SVG string to pdf, write to standard output echo "<svg height='30' width='30'><text y='10'>123</text></svg>" \ | cairosvg -
API
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.
相关文章推荐
- csharp: word or excel Convert to PDF
- C# word or excel Convert to PDF
- Convert SVG to PDF
- Convert SVG to PDF by using iText in Java(ZT)
- Convert SVG to PDF by using iText in Java(ZT)
- Convert SVG to PNG in Python - Stack Overflow
- Convert multiline equation from PDF generated from Latex to PNG
- csharp: word or excel Convert to PDF
- csharp: word or excel Convert to PDF
- Convert polygon faces to triangles or quadrangles
- gen already exists but is not a source folder. Convert to a source folder or rename it
- gen already exists but is not a source folder. Convert to a source folder or rename it 的解决办法
- To convert QString to LPTSTR or LPCTSTR:
- /gen already exists but is not a source folder. Convert to a source folder or rename it.
- 两个比较好用的C#转VB.NET工具(Convert C# to VB.NET or Convert VB.NET to C#)
- gen already exists but is not a source folder. Convert to a source folder or rename it.
- Convert HTML to PDF with New Plugin
- gen already exists but is not a source folder. Convert to a source folder or rename it 的解决办法
- gen already exists but is not a source folder. Convert to a source folder or rename it.
- gen already exists but is not a source folder. Convert to a source folder or rename it.