Convert SVG to PDF in C#

IronPDF has extensive support for rendering SVG graphics into PDF documents via the "HTML to PDF" methodology.

Please note that it is important to set the width and/or height style attribute of the img element when embedding an SVG - otherwise, it may collapse to zero size and not appear in the rendered PDF.

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;

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

ChromePdfRenderer renderer = new ChromePdfRenderer();
renderer.RenderingOptions.WaitFor.RenderDelay(1000);

PdfDocument pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("svgToPdf.pdf");
Imports IronPdf

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

Private renderer As New ChromePdfRenderer()
renderer.RenderingOptions.WaitFor.RenderDelay(1000)

Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html)
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.

Ready to see what else you can do? Check out our tutorial page here: Addtional Features

Frequently Asked Questions

How can I convert SVG to PDF in C#?

To convert SVG to PDF in C#, install the IronPDF library, embed the SVG using the img tag in HTML, set explicit width and height attributes, and then use IronPDF's rendering methods to generate and save the PDF using the SaveAs method.

Why is it necessary to define width and height for SVGs when converting to PDF?

Defining width and height for SVGs when converting to PDF with IronPDF is crucial because the rendering engine requires explicit size attributes to prevent the SVG from collapsing to a zero-size in the output PDF.

What are the steps to render SVGs into PDFs using IronPDF?

The steps include installing the IronPDF library, embedding the SVG in an HTML img tag with specified width and height, using IronPDF's rendering methods, and saving the document with the SaveAs method.

Can I convert SVGs to PDFs without specifying size attributes?

While some browsers can display SVGs without size attributes, IronPDF requires explicit width and height attributes to correctly render SVGs into PDFs.

Are there examples of SVG styling that can be used with IronPDF?

Yes, you can refer to styling examples of SVGs on platforms like CodePen, which can be adapted when using IronPDF for consistent rendering in PDFs.

How do I troubleshoot issues with SVGs not appearing in PDFs?

Ensure that the SVG has explicit width and height attributes defined and that the IronPDF library is correctly installed and referenced in your C# project. These steps help prevent SVGs from collapsing to zero size in the PDF.

What programming language is used in the example for SVG to PDF conversion?

The example for SVG to PDF conversion using IronPDF is provided in C#.

Is a trial version of the PDF library available for testing?

Yes, a trial version of IronPDF is available for download from the NuGet package repository, allowing you to test SVG to PDF conversions.

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.