Get started with IronPDF

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer


Render SVG to PDF Example

Many browsers are tolerant of SVGs having no size; however, our rendering engine is sensitive to this.

:path=/static-assets/pdf/content-code-examples/how-to/SVGs-render.cs
using IronPdf;

// Define the HTML content to be included in the PDF. In this case, it's an image with a specified width.
string html = "<img src='https://ironsoftware.com/img/svgs/new-banner-svg.svg' style='width:100px'>";

// Create a new instance of ChromePdfRenderer, which is used to convert HTML to PDF.
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Set rendering options to ensure any dynamic content, such as JavaScript-rendered elements, has time to load.
// Here, we set a render delay of 1000 milliseconds (1 second) to allow dynamic content to completely load.
renderer.RenderingOptions.RenderDelay = 1000;

// Render the HTML content to a PDF document.
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);

// Save the generated PDF document to a file named "svgToPdf.pdf" in the current directory.
pdf.SaveAs("svgToPdf.pdf");
Imports IronPdf



' Define the HTML content to be included in the PDF. In this case, it's an image with a specified width.

Private html As String = "<img src='https://ironsoftware.com/img/svgs/new-banner-svg.svg' style='width:100px'>"



' Create a new instance of ChromePdfRenderer, which is used to convert HTML to PDF.

Private renderer As New ChromePdfRenderer()



' Set rendering options to ensure any dynamic content, such as JavaScript-rendered elements, has time to load.

' Here, we set a render delay of 1000 milliseconds (1 second) to allow dynamic content to completely load.

renderer.RenderingOptions.RenderDelay = 1000



' Render the HTML content to a PDF document.

Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html)



' Save the generated PDF document to a file named "svgToPdf.pdf" in the current directory.

pdf.SaveAs("svgToPdf.pdf")
$vbLabelText   $csharpLabel

Output PDF

Additionally, or alternatively, an SVG node may have an explicit width and height attribute assigned. Please also see examples of SVG styling on CodePen.

Frequently Asked Questions

What is this library used for rendering SVG graphics into PDF documents?

IronPDF is a library that supports rendering SVG graphics into PDF documents using the 'HTML to PDF' methodology.

How do I install the library for SVG to PDF conversion?

You can install IronPDF for SVG to PDF conversion by downloading it from the NuGet package repository.

Why do SVG images need width and height attributes?

SVG images need width and height attributes to prevent them from collapsing to zero size in the rendered PDF.

Can I use SVG images without explicit size attributes?

While many browsers can handle SVGs without size attributes, IronPDF's rendering engine requires explicit width and height attributes.

How do I convert SVG to PDF in C#?

To convert SVG to PDF using IronPDF in C#, embed the SVG in an HTML  related to How do I convert SVG to PDF in C#? tag with specified width and height, render the HTML to PDF with IronPDF, and save the resulting PDF document.

What method is used to save the PDF file in the library?

The 'SaveAs' method is used to save the PDF file in IronPDF.

Can I see examples of SVG styling?

Yes, examples of SVG styling can be seen on CodePen as referenced in the webpage.

What programming language is used in the provided example?

The provided example for converting SVG to PDF uses C#.

Is there a trial version available for the library?

Yes, a trial version of IronPDF is available for download from the NuGet package repository.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.