Convert SVG Graphics to PDF Pages
Aspose.HTML for Python via .NET
converts an SVG file or URL with
SVGDocument
,
PdfSaveOptions
, and
Converter.convert_svg()
.
PDF uses fixed pages, while SVG uses a viewport and scalable coordinates. Configure the PDF page size and margins to fit the artwork instead of relying only on the SVG filename or extension.
Convert SVG to PDF and View the Python Code
Choose an SVG file or URL and keep PDF selected. The widget creates a PDF and provides matching Python code.
{{#if_output 'PDF' 'XPS'}}
import aspose.html.converters as conv
import aspose.html.dom.svg as ahsvg
import aspose.html.saving as sav
{{/if_output}}
{{#if_output 'BMP' 'JPEG' 'GIF' 'PNG' 'TIFF'}}
import aspose.html.converters as conv
import aspose.html.dom.svg as ahsvg
import aspose.html.rendering.image as rim
import aspose.html.saving as sav
{{/if_output}}
with ahsvg.SVGDocument("{{input lower}}") as document:
{{#if_output 'PDF'}}
options = sav.PdfSaveOptions()
{{/if_output}}
{{#if_output 'XPS'}}
options = sav.XpsSaveOptions()
{{/if_output}}
{{#if_output 'BMP' 'JPEG' 'GIF' 'PNG' 'TIFF'}}
options = sav.ImageSaveOptions(rim.ImageFormat.{{output param2 upper}})
{{/if_output}}
conv.Converter.convert_svg(document, options, "output.{{output lower}}")
The example loads input.svg, uses default PdfSaveOptions, and writes output.pdf. Add page, metadata, security, or image-quality settings only when required.
Python Code to Convert SVG to PDF
import aspose.html.converters as conv
import aspose.html.dom.svg as ahsvg
import aspose.html.saving as sav
with ahsvg.SVGDocument("input.svg") as document:
options = sav.PdfSaveOptions()
conv.Converter.convert_svg(document, options, "output.pdf")
How to Convert SVG to PDF in Python
- Install
aspose-html-netand load the SVG withSVGDocument. - Create
PdfSaveOptions. - Configure page setup, CSS, metadata, image quality, or security when required.
- Call
Converter.convert_svg()with the document, options, and PDF path. - Close the SVG document.
Configure PDF Pages and SVG Resources
- Page setup: Match the PDF page and margins to the SVG viewport and intended print size.
- Vector and raster content: Vector shapes can remain resolution independent, while embedded raster images and some graphical effects still depend on source resolution.
- Background and CSS: Set the page background and supported media rules required by the result.
- Metadata and security: Configure document information, encryption, passwords, and permissions when needed.
- Resources: Keep linked images, styles, and fonts accessible during loading and conversion.
See
Convert SVG to PDF in Python
and the
PdfSaveOptions API Reference
.
Install Aspose.HTML for Python via .NET
Install the aspose-html-net package from
PyPI
.
Install Aspose.HTML for Python via .NET
pip install aspose-html-net
Review the installation guide and system requirements before deployment. Request a temporary license to test the API without evaluation limitations.
SVG to PDF FAQ
1. Does SVG to PDF conversion preserve vector graphics?
SVG paths, shapes, and text can remain vector content in PDF, while embedded bitmap images and effects that require raster processing remain resolution dependent. Inspect complex filters and external resources in the generated file.
2. Can the PDF page size be matched to the SVG artwork?
Yes. Configure page dimensions and margins through PdfSaveOptions.page_setup so the PDF page fits the SVG viewport or the required print size.
3. Can Python convert an SVG URL directly to PDF?
Yes. Load the accessible URL with SVGDocument and pass the document, PdfSaveOptions, and PDF path to convert_svg().
4. Do SVG animations and scripts remain interactive in PDF?
No. SVG to PDF conversion creates a fixed document representation. Do not expect browser animation, script execution, or SVG interaction to continue in the PDF.
SVG and PDF Conversion Guides
Choose a raster SVG result or convert another source to PDF.