SVG Conversion API for Python
Convert SVG documents into PDF, images, and other formats programmatically with an enterprise-grade Python library.
Professional SVG Rendering and Conversion
SVG’s standout feature is its ability to scale to any size without sacrificing quality. Although all modern browsers support SVG and it seems ideal for the web, some restrictions still exist, which sometimes require converting SVG to other formats.
Aspose.SVG for Python via .NET provides a robust solution for SVG conversion. This library implements a custom rendering engine that treats SVG as a structured document, ensuring that complex objects, filters, and gradients are preserved during the transformation. The Converter class provides easy and convenient conversion of SVG files to popular formats, making it an effective solution.
Online SVG Converter
You can check the fidelity of our rendering engine using the live demo tool. It uses the same Python-based conversion routines to process files. Upload your source SVG, check the output in different formats, and use the provided code to integrate this logic into your own backend systems.
{{#if_output 'PDF' 'XPS'}}
import aspose.svg as assvg
import aspose.svg.converters as conv
import aspose.svg.saving as sav
{{/if_output}}
{{#if_output 'BMP' 'JPG' 'GIF' 'PNG' 'TIFF'}}
import aspose.svg as assvg
import aspose.svg.converters as conv
import aspose.svg.saving as sav
import aspose.svg.rendering.image as rim
{{/if_output}}
# Load an SVG document from a file
doc = assvg.SVGDocument("{{input lower}}")
# Initialize saving options
{{#if_output 'PDF'}}
opt = sav.PdfSaveOptions()
{{/if_output}}
{{#if_output 'XPS'}}
opt = sav.XpsSaveOptions()
{{/if_output}}
{{#if_output 'BMP' 'JPG' 'GIF' 'PNG' 'TIFF'}}
opt = sav.ImageSaveOptions(rim.ImageFormat.{{output param2 upper}})
{{/if_output}}
# Convert the SVG document to {{output upper}}
conv.Converter.convert_svg(doc, opt, "result.{{output lower}}")
Key Technical Features
The library is designed for developers who need deep control over the conversion process:
- Full W3C Support: High-fidelity handling of SVG paths, text, embedded fonts, and complex spatial transforms.
- Advanced CSS Rendering: Accurate computation of inline and external CSS3 styles, including masks and sophisticated filters.
- Batch Processing: Optimized for high-load server environments, enabling automated processing of thousands of documents in a single workflow.
- Standalone Engine: No requirement for Adobe Illustrator, Chrome, or any graphical subsystem installed on the host.
Common Use Cases
- Automated Reporting: Generate professional charts and diagrams in PDF or image format from dynamic SVG data sources.
- Web UI Automation: Transform SVG icons and graphics into multiple PNG/JPEG resolutions for cross-platform app distribution.
- Document Archiving: Convert vector-based technical drawings into standardized, long-term archival formats like PDF.
- On-the-fly Branding: Programmatically update company logos or watermarks within SVG documents before final export.
Installation
Aspose.SVG for Python via .NET is a cross-platform library that enables developers to build applications for Windows, Linux, and macOS. It is fully compatible with Python 3.6 and later versions. The library is optimized for server-side processing and can be easily deployed in headless environments, such as Linux-based Docker containers.
Install the library using PyPI :
Install Aspose.SVG for Python via .NET
pip install aspose-svg-net
For detailed setup instructions, please visit our Documentation .
Supported Conversion Pairs
The library supports a wide range of conversions, including: