CairoSVG - Convert SVG to PNG or PDF - Contents

User Documentation

Author Guillaume Ayoub
Date 2011-02-13

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 filename

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

CairoSVG - Convert SVG to PNG or PDF - Contents的更多相关文章

  1. Convert SVG to PNG in Python - Stack Overflow

    Convert SVG to PNG in Python - Stack Overflow Convert SVG to PNG in Python

  2. C#/VB.NET 将SVG图片添加到PDF、转换为PDF

    以下内容介绍在C# 程序中如何将SVG图片添加到PDF文档.以及如何将SVG图片转换为PDF文档. 一.环境准备 先下载PDF类库工具,Spire.PDF for .NET hotfix 6.5.6及 ...

  3. how to convert SVG shapes to polygon

    how to convert SVG shapes to polygon 如何将 svg 的 rect 转换成 polygon rect.circle.ellipse.line.polyline.po ...

  4. [Tools] Convert SVG to a PDF in Node with PDFKit and SVG.js

    Given a epxress application and an svg template, we want to draw some text, date onto it and convert ...

  5. Gmagick convert SVG to PNG with transparent/opacity background

    1 前言 在Ubuntu18.04环境下,用gographics/gmagick API使用了以下代码未有效果 pw := gmagick.NewPixelWand() pw.SetOpacity(1 ...

  6. convert source code files to pdf format in python

    import os import sys def find_file(root_dir, type): dirs_pool = [root_dir] dest_pool = [] def scan_d ...

  7. Batik - 将svg转换成其他格式图片或PDF - [导出服务器配置] 导出服务器原理解析

    导出服务器原理解析 Highcharts图表导出(或下载)本质上是将SVG代码转换为不同文件格式的过程,用到的工具是batik,所以所谓导出服务器,只不过是调用batik,将SVG代码转换并下载.下图 ...

  8. C# 将PDF转为SVG的3种情况

    PDF格式的文档广泛用于各种办公场所,在工作中难免会有将PDF文档转换为其他文档格式的需要.在本篇文档中,将介绍PDF转为SVG的方法.根据不同的转换需求,这里分三种情况进行讲述,即转PDF所有页为S ...

  9. Java 将PDF 转为Word、图片、SVG、XPS、Html、PDF/A

    本文将介绍通过Java编程来实现PDF文档转换的方法.包括: 1. PDF转为Word 2. PDF转为图片 3. PDF转为Html 4. PDF转为SVG 4.1 将PDF每一页转为单个的SVG ...

随机推荐

  1. win7 64位下如何安装配置mysql-5.7.4-m14-winx64

    win7 64位下如何安装配置mysql-5.7.4-m14-winx641. mysql-5.7.4-m14-winx64.zip下载 官方网站下载地址:http://dev.mysql.com/g ...

  2. 对面向对象的理解—— SAP电面(1)

    对于C++面向对象的理解 面向对象是在结构化设计方法出现很多问题的情况下应运而生的.结构化设计方法求解问题的基本策略是从功能的角度审视问题域.它将应用程序看成实现某些特定任务的功能模块,其中子过程是实 ...

  3. JavaSE学习总结第24天_多线程2

      24.01  JDK5之后的Lock锁的概述和使用 虽然我们可以理解同步代码块和同步方法的锁对象问题,但是我们并没有直接看到在哪里加上了锁,在哪里释放了锁,为了更清晰的表达如何加锁和释放锁,JDK ...

  4. codeforces 464C. Substitutes in Number

    题目链接 C. Substitutes in Number time limit per test 1 second memory limit per test 256 megabytes input ...

  5. JS实现常用的分享到按钮

    我们阅读博客的时候经常会用到这样功能,当然有时候也会想把自己的网站上也加入类似的分享功能,各大厂商已经给出了相应的API,点击一个按钮即可弹出窗口进入分享,我们事先可以设置一些参数,一般常用的就是 网 ...

  6. Qt中的对象类型转换(Qstring 转换char*有三种方法)

    char * 与 const char *的转换 char *ch1="hello11"; const char *ch2="hello22"; ch2 = c ...

  7. poj 1068 Parencodings(栈)

    题目链接:http://poj.org/problem?id=1068 思路分析:对栈的模拟,将栈中元素视为广义表,如 (((()()()))),可以看做 LS =< a1, a2..., a1 ...

  8. FileUtil

    package com.wiseweb.util; import java.io.BufferedReader; import java.io.File; import java.io.FileInp ...

  9. AWS要进入中国了

    去年底就开始有这个传言见诸于某些媒体,说网站支持中文了要进中国了,也有说这不代表什么是谣言 这几天又听到有消息说比较靠谱就半年内的事儿 其实如果没有政策阻碍的话进中国是迟早的事情,原因如下 Amazo ...

  10. [Swust OJ 1094]--中位数(巧用set,堆排序)

    题目链接:http://acm.swust.edu.cn/problem/1094/ Time limit(ms): 1000 Memory limit(kb): 32768   中位数(又称中值,英 ...