Convert SVG to PDF in C#
IronPDF converts SVG graphics to PDF documents using the HTML to PDF approach - embed your SVG in an img tag with explicit width/height styles to ensure proper rendering.
IronPDF supports rendering SVG graphics into PDF documents via the HTML to PDF method. SVG (Scalable Vector Graphics) files are widely used for logos, icons, illustrations, and charts due to their scalability and crisp rendering at any size. Converting SVGs to PDFs is essential for creating print-ready documents, archival purposes, and ensuring consistent display across different platforms.
Note: 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.
Convert SVG files to PDF using IronPDF in C#. This snippet demonstrates embedding an SVG via an HTML img tag with specified dimensions, a crucial step for successful rendering. Follow this guide for a quick implementation that ensures your SVGs are accurately rendered and saved as PDFs.
-
1Install IronPDF with NuGet Package Manager
-
2Copy and run this code snippet.
new IronPdf.ChromePdfRenderer { RenderingOptions = { WaitFor = IronPdf.Rendering.WaitFor.RenderDelay(1000) } } .RenderHtmlAsPdf("<img src='https://example.com/logo.svg' style='width:100px;height:100px;'>") .SaveAs("svgToPdf.pdf");C# -
3Deploy to test on your live environment
Start using IronPDF in your project today with a free trial
Minimal Workflow (5 steps)
- Install
IronPdfLibrary for SVG to PDF Conversion - Use
imgtag in HTML to import SVG image - Utilize different rendering methods in
IronPdfto generate PDF - Save the PDF file containing SVG image with
SaveAsmethod - Check the PDF in specified location
How Do I Render SVG to PDF with Proper Sizing?
Many browsers tolerate SVGs without size specifications; however, our rendering engine requires them. The Chrome rendering engine used by IronPDF requires explicit dimensions to properly render SVG elements. Without specified dimensions, the SVG may not appear in the final PDF or may render with unexpected sizing.
When working with SVGs in IronPDF, you have several options for ensuring proper rendering:
- Inline SVG with Style Attributes: Add
widthandheightdirectly in the style attribute - External SVG Files: Reference SVG files via URL or local file path
- Base64 Encoded SVGs: Embed SVGs directly in the HTML as Base64 strings
For more advanced HTML rendering options, see our comprehensive guide on rendering options.
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")What Does the Generated PDF Look Like?
Additionally, or alternatively, an SVG node may have an explicit width and height attribute assigned. See also examples of SVG styling on CodePen.
Render SVG to PDF Example
Working with Local SVG Files
When converting local SVG files to PDF, use the file path approach. This method works well with SVG assets stored in your project:
using IronPdf;
using System.IO;
// Load SVG file content
string svgPath = @"C:\assets\company-logo.svg";
string svgContent = File.ReadAllText(svgPath);
// Create HTML with embedded SVG
string html = $@"
<html>
<head>
<style>
body {{ margin: 20px; }}
.logo {{ width: 200px; height: 100px; }}
</style>
</head>
<body>
<h1>Company Report</h1>
<img src='file:///{svgPath}' class='logo' />
<p>Annual financial summary with vector graphics.</p>
</body>
</html>";
// Configure renderer with custom settings
ChromePdfRenderer renderer = new ChromePdfRenderer();
renderer.RenderingOptions.MarginTop = 10;
renderer.RenderingOptions.MarginBottom = 10;
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
// Generate PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("report-with-svg.pdf");Imports IronPdf
Imports System.IO
' Load SVG file content
Dim svgPath As String = "C:\assets\company-logo.svg"
Dim svgContent As String = File.ReadAllText(svgPath)
' Create HTML with embedded SVG
Dim html As String = $"
<html>
<head>
<style>
body {{ margin: 20px; }}
.logo {{ width: 200px; height: 100px; }}
</style>
</head>
<body>
<h1>Company Report</h1>
<img src='file:///{svgPath}' class='logo' />
<p>Annual financial summary with vector graphics.</p>
</body>
</html>"
' Configure renderer with custom settings
Dim renderer As New ChromePdfRenderer()
renderer.RenderingOptions.MarginTop = 10
renderer.RenderingOptions.MarginBottom = 10
renderer.RenderingOptions.PrintHtmlBackgrounds = True
' Generate PDF
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("report-with-svg.pdf")Base64 Encoding for Embedded SVGs
For scenarios requiring SVG data embedded directly in HTML without external file references, Base64 encoding provides a reliable solution. This approach is explained in detail in our embedding images guide:
using IronPdf;
using System;
// SVG content as string
string svgContent = @"<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>
<circle cx='50' cy='50' r='40' stroke='black' stroke-width='2' fill='red' />
</svg>";
// Convert to Base64
byte[] svgBytes = System.Text.Encoding.UTF8.GetBytes(svgContent);
string base64Svg = Convert.ToBase64String(svgBytes);
// Create HTML with Base64 embedded SVG
string html = $@"
<html>
<body>
<h2>Embedded SVG Example</h2>
<img src='data:image/svg+xml;base64,{base64Svg}' style='width:150px;height:150px;' />
</body>
</html>";
// Render to PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("embedded-svg.pdf");Imports IronPdf
Imports System
Imports System.Text
' SVG content as string
Dim svgContent As String = "<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>
<circle cx='50' cy='50' r='40' stroke='black' stroke-width='2' fill='red' />
</svg>"
' Convert to Base64
Dim svgBytes As Byte() = Encoding.UTF8.GetBytes(svgContent)
Dim base64Svg As String = Convert.ToBase64String(svgBytes)
' Create HTML with Base64 embedded SVG
Dim html As String = $"
<html>
<body>
<h2>Embedded SVG Example</h2>
<img src='data:image/svg+xml;base64,{base64Svg}' style='width:150px;height:150px;' />
</body>
</html>"
' Render to PDF
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("embedded-svg.pdf")Best Practices for SVG to PDF Conversion
1. Always Specify Dimensions
The most common issue when converting SVGs to PDF is missing or zero dimensions. Always ensure your SVG elements have explicit width and height values. For responsive designs, consider using viewport settings to control PDF layout.
2. Handle Complex SVGs with Render Delays
Complex SVG files with animations or JavaScript may require additional rendering time. Use the RenderDelay option to ensure complete rendering:
renderer.RenderingOptions.WaitFor.RenderDelay(2000); // Wait 2 secondsrenderer.RenderingOptions.WaitFor.RenderDelay(2000) ' Wait 2 secondsFor advanced JavaScript handling, explore our JavaScript rendering guide.
3. Optimize SVG Files
Before conversion, optimize your SVG files by:
- Removing unnecessary metadata
- Simplifying paths
- Converting text to paths for consistent rendering
- Using appropriate compression
4. Test Cross-Platform Compatibility
SVG rendering may vary across different operating systems. Test your conversions on:
The IronSuite play a crucial role in our operations. These are tools that increase efficiencies across the business including creating floor plans and improving inventory management.
Troubleshooting Common SVG Issues
SVG Not Appearing in PDF
If your SVG doesn't appear in the generated PDF:
- Verify dimensions are set correctly
- Check file paths or URLs are accessible
- Ensure proper MIME type for SVG files
- Review our pixel-perfect rendering guide
Scaling and Resolution Problems
For high-quality SVG rendering at different scales:
// Increase viewport width and zoom for higher-fidelity vector rendering
renderer.RenderingOptions.ViewPortWidth = 1920;
renderer.RenderingOptions.Zoom = 150;
// Use CSS transforms for scaling
string html = @"
<img src='logo.svg' style='width:200px;height:200px;transform:scale(1.5);' />";
Font Rendering in SVGs
When SVGs contain text elements, ensure fonts are properly embedded. Learn more about font management and web font support.
Advanced SVG Conversion Techniques
Batch Processing Multiple SVGs
For converting multiple SVG files to a single PDF document:
using IronPdf;
using System.Collections.Generic;
using System.Text;
List<string> svgFiles = new List<string>
{
"chart1.svg",
"chart2.svg",
"diagram.svg"
};
StringBuilder htmlBuilder = new StringBuilder();
htmlBuilder.Append("<html><body>");
foreach(string svgFile in svgFiles)
{
htmlBuilder.Append($@"
<div style='page-break-after:always;'>
<img src='{svgFile}' style='width:600px;height:400px;' />
</div>");
}
htmlBuilder.Append("</body></html>");
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlBuilder.ToString());
pdf.SaveAs("multiple-svgs.pdf");Imports IronPdf
Imports System.Collections.Generic
Imports System.Text
Dim svgFiles As New List(Of String) From {
"chart1.svg",
"chart2.svg",
"diagram.svg"
}
Dim htmlBuilder As New StringBuilder()
htmlBuilder.Append("<html><body>")
For Each svgFile As String In svgFiles
htmlBuilder.Append($"
<div style='page-break-after:always;'>
<img src='{svgFile}' style='width:600px;height:400px;' />
</div>")
Next
htmlBuilder.Append("</body></html>")
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(htmlBuilder.ToString())
pdf.SaveAs("multiple-svgs.pdf")For more information on working with multiple pages, see our merge or split PDFs guide.
Ready to see what else you can do? Check out our tutorial page here: Additional Features. You can also explore how to add headers and footers to your SVG-containing PDFs or learn about custom watermarks for branding your documents.
- Use
TextAnnotationandAddTextAnnotation
Frequently Asked Questions
How can I convert an SVG to a PDF in C# using IronPDF?
To convert an SVG to a PDF in C#, you can use IronPDF's HTML to PDF rendering method. Simply embed your SVG within an HTML `img` tag with defined `width` and `height` attributes. This ensures that the SVG appears correctly in the PDF.
Why is specifying dimensions for SVGs important in IronPDF?
Specifying dimensions for SVGs is crucial when using IronPDF because without explicit `width` and `height` settings, the SVG may collapse to zero size and not appear correctly in the final PDF. Proper dimension specifications ensure accurate rendering.
What is a quick way to render an SVG to PDF using IronPDF?
A quick way to render an SVG to PDF is by using the `ChromePdfRenderer` class in IronPDF. By setting a render delay and embedding the SVG in an HTML `img` tag with defined dimensions, you can easily generate a PDF.
Can I use a local SVG file for conversion to PDF in IronPDF?
Yes, you can convert a local SVG file to PDF using IronPDF by referencing the SVG file path within the HTML `img` tag. Make sure the SVG file path is accessible and properly cited.
Is it possible to embed SVGs directly in HTML using IronPDF?
Yes, you can embed SVGs directly in HTML using Base64 encoding. This eliminates the need for external file references and ensures that the SVG is embedded directly within the HTML content rendered by IronPDF.
What solutions are available for rendering complex SVGs with IronPDF?
For rendering complex SVGs, using a `RenderDelay` is recommended. This allows IronPDF's rendering engine additional time to fully process and display all elements correctly, including animations or dynamic content.
How does IronPDF handle font rendering in SVGs?
IronPDF requires that fonts used within SVGs are properly embedded or referenced to ensure correct text rendering. You can manage fonts through IronPDF's font management features to guarantee consistency.
What are best practices for converting SVGs to PDF?
Best practices include specifying SVG dimensions, optimizing SVG files by simplifying paths and removing unnecessary metadata, and testing across different platforms to ensure consistent rendering with IronPDF.
How can I convert multiple SVG files into a single PDF using IronPDF?
To convert multiple SVGs into a single PDF, use IronPDF to embed each SVG in a separate HTML element with a page-break style for continuous PDF generation. This facilitates batch processing of SVGs.
Does IronPDF support responsive design for SVG to PDF conversion?
Yes, IronPDF supports responsive design elements by using viewport settings and CSS transformations. This allows for scalable and dynamically adjusted PDF layouts based on the SVG content you are converting.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.