Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Quick Answer: Aspose.SVG for Python via .NET converts SVG to PDF, PNG, JPG, BMP, TIFF, GIF, and XPS. Use Converter.convert_svg() for direct file conversion, or load an SVGDocument and call render_to(device) when you need a rendering-device workflow.
SVG is ideal for scalable graphics, but many workflows require fixed output formats. Use PDF for print and document exchange, PNG or JPG for web previews and raster assets, TIFF or BMP for image pipelines, GIF for simple raster output, and XPS for fixed-layout document workflows.
This page gives a short overview of the SVG conversion API. For detailed options and format-specific examples, use the linked articles below.
| Output format | Typical use | Detailed article |
|---|---|---|
| Print, archiving, document exchange | Convert SVG to PDF | |
| PNG | Web images, transparent raster output, previews | Convert SVG to PNG |
| JPG | Raster previews without transparency | Convert SVG to JPG |
| BMP | Simple bitmap output | Convert SVG to Image |
| TIFF | Multi-purpose raster workflows and publishing | Convert SVG to Image |
| GIF | Lightweight raster output | Convert SVG to Image |
| XPS | Fixed-layout document output | See the XPS example below |
The
Converter class is the easiest way to convert SVG files. Create save options for the target format, load the SVG document with SVGDocument, and call Converter.convert_svg().
1from aspose.svg import SVGDocument
2from aspose.svg.converters import Converter
3from aspose.svg.saving import ImageSaveOptions
4
5# Convert SVG to PNG using the high-level converter API
6options = ImageSaveOptions()
7
8with SVGDocument("image.svg") as document:
9 Converter.convert_svg(document, options, "image.png")XPS is a niche fixed-layout output format. Use it when a Windows document, print, or archival workflow specifically requires XPS. For most document exchange scenarios, PDF is usually the better default.
1from aspose.svg import SVGDocument
2from aspose.svg.converters import Converter
3from aspose.svg.saving import XpsSaveOptions
4
5# Convert SVG to XPS when the target workflow requires XPS output
6options = XpsSaveOptions()
7
8with SVGDocument("document.svg") as document:
9 Converter.convert_svg(document, options, "document.xps")The
render_to() method sends SVG content to a rendering device. Use this workflow when your application needs explicit control over a target device such as
PdfDevice, XpsDevice, or
ImageDevice.
1import os
2from aspose.svg import SVGDocument
3from aspose.svg.rendering.pdf import PdfDevice, PdfRenderingOptions
4
5# Render SVG to PDF using a rendering device
6input_folder = "data/"
7output_folder = "output/"
8input_path = os.path.join(input_folder, "document.svg")
9output_path = os.path.join(output_folder, "document.pdf")
10os.makedirs(output_folder, exist_ok=True)
11
12options = PdfRenderingOptions()
13options.jpeg_quality = 80
14
15with SVGDocument(input_path) as document:
16 with PdfDevice(options, output_path) as device:
17 document.render_to(device)Most SVG conversion tasks use save options or rendering options to control output quality, page setup, background color, and resource handling.
| Option group | Used with | Examples |
|---|---|---|
| ImageSaveOptions | PNG, JPG, BMP, TIFF, GIF output | Image format, background color, page setup, resolution |
| PdfSaveOptions | PDF output through Converter.convert_svg() | Page setup, JPEG quality, metadata, encryption, background color |
| XpsSaveOptions | XPS output through Converter.convert_svg() | Page setup, background color, resolution |
| PdfRenderingOptions | PDF output through PdfDevice | Page setup, JPEG quality, resolution, background color |
RenderingOptions | Device-based rendering workflows | Common rendering settings inherited by format-specific options |
Batch conversion uses the same APIs as single-file conversion. Iterate through a folder of SVG files, create an output path for each file, and call Converter.convert_svg() for every document. See
Batch Convert SVG Files in Python for PNG, JPG, and PDF examples.
Use the free online SVG Converter to test SVG conversion before implementing it in Python. Upload an SVG file, select an output format, and compare the generated file.
| Problem | Likely cause | Fix |
|---|---|---|
| Output file is missing | The output folder does not exist or the file was saved in another working directory | Create the folder with os.makedirs() and use explicit paths |
| Converted image has the wrong background | The SVG contains transparent areas and no background was configured | Set the background color in the save or rendering options |
| PDF or image size is unexpected | Page setup does not match the SVG viewport or content bounds | Configure page size, margins, or sizing mode in the relevant options object |
| External images or fonts are missing | Relative resources cannot be resolved during conversion | Keep resources next to the SVG or use correct absolute paths/base paths |
| Output is too large | The SVG is complex or raster settings are too high | Reduce resolution, JPEG quality, image size, or simplify the SVG before conversion |
How do I convert SVG files in Python?
Use SVGDocument to load the file, create save options for the target format, and call Converter.convert_svg().
Which SVG output formats are supported?
Aspose.SVG for Python via .NET supports conversion to PDF, XPS, PNG, JPG, BMP, TIFF, and GIF.
Should I use Converter.convert_svg() or render_to()?
Use Converter.convert_svg() for ordinary file conversion. Use render_to() when you need a rendering-device workflow with PdfDevice, XpsDevice, or ImageDevice.
Can I convert SVG from a URL?
Yes. Load the SVG URL with SVGDocument when network access is available, then convert it with the same API used for local files.
Can I convert SVG to XPS in Python?
Yes. Create XpsSaveOptions and pass it with the loaded SVGDocument to Converter.convert_svg(). Use XPS only when your target workflow requires that format.
Can I batch convert multiple SVG files?
Yes. Loop through the input folder, load each .svg file with SVGDocument, and call Converter.convert_svg() for each output file.
Can I change the output size during conversion?
Yes. Configure page setup, sizing, margins, and resolution through the target format’s save or rendering options.
PdfDevice rendering.Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.