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. BZOJ 1863: [Zjoi2006]trouble 皇帝的烦恼( 二分答案 )

    二分答案..然后从头到尾推一下, 看最后一个能不能取0个和第一个人相同的勋章 ------------------------------------------------------------- ...

  2. BZOJ 2015: [Usaco2010 Feb]Chocolate Giving( 最短路 )

    裸最短路.. ------------------------------------------------------------------------------------ #include ...

  3. Css小技巧-图片垂直居中

    说明:样式设置主要是针对图片的父级元素,并非图片元素本身. Css代码[图片父级点的样式]: <style> .box { /*非IE的主流浏览器识别的垂直居中的方法*/ display: ...

  4. 使用yum来下载RPM包而不进行安装

    1. 安装yum-downloadonly. yum-utils 或 yum-plugin-downloadonly 软件包 (RHEL5) # yum install yum-downloadonl ...

  5. 华为GVRP理解

    类似于CISCO的VTP 在大型的网络中,华为交换机之间的串联是很普遍的.一般交换机互联端口都是配置成Trunk,即允许透传多个VLAN的.对于用户来说,手工配置太麻烦.一个规模比较大的网络可能包含多 ...

  6. linux 内核分析之list_head

    转自:http://www.cnblogs.com/riky/archive/2006/12/28/606242.html 一.链表数据结构简介 链表是一种常用的组织有序数据的数据结构,它通过指针将一 ...

  7. Android 使用动态载入框架DL进行插件化开发

    如有转载,请声明出处: 时之沙: http://blog.csdn.net/t12x3456    (来自时之沙的csdn博客) 概述: 随着应用的不断迭代.应用的体积不断增大,项目越来越臃肿,冗余添 ...

  8. Codeforces 57C Array dp暴力找到规律

    主题链接:点击打开链接 的非增量程序首先,计算, 如果不增加的节目数量x, 非减少一些方案是x 答案就是 2*x - n 仅仅需求得x就可以. 能够先写个n3的dp,然后发现规律是 C(n-1, 2* ...

  9. 读懂Swift 2.0中字符串设计思路的改变

    Swift提供了一种高性能的,兼容Unicode编码的String实现作为标准库的一部分.在 Swift2中,String类型不再遵守CollectionType协议.在以前,String类型是字符的 ...

  10. Xcode 静态库调试策略

    Xcode 静态库调试策略  (已经有现成的工程和静态库源码)    ***** 为安全期间建议备份一下静态库 Step1: 下载最新的工程[工程中有所要测试的静态库和头文件需要删除]: Step2: ...