SVG to PDF in Python
SVG is widely used in website building and print graphics due to its scalability. However, sometimes you need to convert an SVG document to PDF format. With Aspose.SVG for Python via .NET API, you can programmatically convert SVG to PDF while maintaining full control over various conversion parameters. This powerful Python API enables high-speed, high-quality conversion of SVG to other formats. Try it right now!
Free Online SVG Converter
You can test the quality of SVG to PDF conversion directly in your browser! Load an SVG file from your local file system, select the PDF output format, and run the example. You will instantly receive the result as a separate PDF file. Additionally, you will find a Python example demonstrating how to convert an SVG document. The provided source code illustrates how to read an SVG from a file and convert it to PDF format using default saving options.
{{#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}}")
This code demonstrates how to convert an SVG to PDF using the Aspose.SVG Python library. It involves setting up the necessary rendering extension, configuring saving options, loading the SVG document, and performing the conversion. Please visit our Documentation to learn more about using Aspose.SVG API conversion functions and to consider Python examples for the most common SVG conversion scenarios.
How to Convert SVG to PDF
Follow the easy steps to convert SVG to PDF format:
- Install Aspose.SVG for Python via .NET. For example, install from the command line as
pip install aspose-svg-net. - Load an SVG file in Python using the SVGDocument class.
- Create an instance of PdfSaveOptions , which holds the configuration for saving the resulting PDF file.
- Use the
convert_svg()method of the Converter class to convert the loaded SVG document to PDF format. Passed parameters:doc– the loaded SVG document;opt– the PDF saving options;"result.pdf"– the output PDF file name.
- Get the result of SVG to PDF conversion.
Get Started with Python API
If you want to develop scalable vector graphics and their applications, install our flexible, high-speed Aspose.SVG for Python via .NET API. pip is the easiest way to download and install Aspose.SVG for Python via .NET API. To do this, run the following command:
pip install aspose-svg-net
For more details about Python library installation and system requirements, please refer to Aspose.SVG Documentation.
Other Features of Aspose.SVG for Python via .NET
Use the Aspose.SVG Python library to convert, merge, edit SVG documents, vectorize images, and more!