IRONSOFTWAREHOME

Convert SVG to PDF in C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

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.

Quickstart: Effortless SVG to PDF Conversion

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.

  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 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#
  3. 3Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

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:

  1. Inline SVG with Style Attributes: Add width and height directly in the style attribute
  2. External SVG Files: Reference SVG files via URL or local file path
  3. 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");

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");

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");

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 seconds

For 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:

My favorite library of this kind is IronPDF. It allows for fast and efficient manipulation of PDF files. It also has many valuable features, like exporting to PDF/A format and digitally signing PDF documents.

Milan Jovanovic

Microsoft MVP

View case study

IronOCR means we can save $40,000 annually from manual processing, while enhancing productivity and freeing up resources for high-impact tasks. I would highly recommend it.

Brent Matzelle

Chief Technology Officer, OPYN

View case study

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.

David Jones

Lead Software Engineer, Agorus Build

View case study

Troubleshooting Common SVG Issues

SVG Not Appearing in PDF

If your SVG doesn't appear in the generated PDF:

  1. Verify dimensions are set correctly
  2. Check file paths or URLs are accessible
  3. Ensure proper MIME type for SVG files
  4. 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);' />";
C#

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");

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 TextAnnotation and AddTextAnnotation

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
Technical Writer

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.

...
Read More

Ready to Get Started?

Nuget Downloads 20,809,720Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required