How to Convert PDF to SVG in C#

This article was translated from English: Does it need improvement?
Translated
View the article in English

The PdfToSvg namespace in IronPDF provides a dedicated API for converting PDF pages to scalable vector graphics. SVG (Scalable Vector Graphics) is an XML-based format that stays sharp at any zoom level: unlike raster images (PNG, JPEG), SVG output does not pixelate when scaled up. Converting PDF pages to SVG is useful for embedding document content in web pages, generating resolution-independent previews, and extracting vector graphics from reports, invoices, or technical drawings.

The conversion works per-page: open a PDF with PdfDocument.Open(), access individual pages through the Pages collection, then call SaveAsSvg() or ToSvgString() on each PdfPage to produce SVG output. Async variants are available for all conversion methods.

This is the PDF-to-SVG direction: extracting vector SVG from existing PDF files. For the reverse workflow (embedding SVG graphics into a new PDF), see the SVG to PDF how-to.

Start a free 30-day trial to test PDF-to-SVG conversion.

NuGet Installer avec NuGet

PM >  Install-Package IronPdf

Consultez IronPDF sur NuGet pour une installation rapide. Avec plus de 10 millions de téléchargements, il transforme le développement PDF avec C#. Vous pouvez également télécharger le DLL ou l'installateur Windows.

The example below opens a PDF and saves its first page as an SVG file.

  1. Installez IronPDF avec le Gestionnaire de Packages NuGet

    PM > Install-Package IronPdf
  2. Copiez et exécutez cet extrait de code.

    using PdfToSvg;
    
    using var pdf = PdfDocument.Open("report.pdf");
    pdf.Pages[0].SaveAsSvg("page-one.svg");
  3. Déployez pour tester sur votre environnement de production.

    Commencez à utiliser IronPDF dans votre projet dès aujourd'hui avec un essai gratuit

    arrow pointer

Quickstart

Minimal Workflow (3 Steps)

  1. Install IronPDF via NuGet: Install-Package IronPdf
  2. Open a PDF with PdfDocument.Open() from the PdfToSvg namespace
  3. Call SaveAsSvg() on any page to write the SVG file

How to Convert a Single PDF Page to SVG?

The PdfPage class provides four conversion methods:

  • SaveAsSvg(): writes the page to a file path or Stream.
  • SaveAsSvgAsync(): the non-blocking variant of SaveAsSvg().
  • ToSvgString(): returns the SVG markup as a string, useful when the output feeds a template engine, an HTTP response, or a downstream pipeline.
  • ToSvgStringAsync(): the non-blocking variant of ToSvgString().

All four accept an optional SvgConversionOptions argument and a CancellationToken.

The example below saves the first page to a file, gets the same page back as a string, and writes it to a stream. It shows all three output targets.

:path=/static-assets/pdf/content-code-examples/how-to/pdf-to-svg-single-page.cs
using PdfToSvg;

using var pdf = PdfDocument.Open("invoice.pdf");

// Save to a file
pdf.Pages[0].SaveAsSvg("invoice-page1.svg");

// Get SVG as a string
string svgMarkup = pdf.Pages[0].ToSvgString();
Console.WriteLine($"SVG length: {svgMarkup.Length} characters");

// Save to a stream
using var stream = new FileStream("invoice-page1-stream.svg", FileMode.Create);
pdf.Pages[0].SaveAsSvg(stream);
Imports PdfToSvg
Imports System.IO

Using pdf = PdfDocument.Open("invoice.pdf")
    ' Save to a file
    pdf.Pages(0).SaveAsSvg("invoice-page1.svg")

    ' Get SVG as a string
    Dim svgMarkup As String = pdf.Pages(0).ToSvgString()
    Console.WriteLine($"SVG length: {svgMarkup.Length} characters")

    ' Save to a stream
    Using stream As New FileStream("invoice-page1-stream.svg", FileMode.Create)
        pdf.Pages(0).SaveAsSvg(stream)
    End Using
End Using
$vbLabelText   $csharpLabel

PdfDocument implements IDisposable, so wrapping it in a using statement releases native resources when the conversion is finished. The Pages collection is zero-indexed, so Pages[0] is the first page.

Veuillez noterPdfToSvg.PdfDocument is a distinct class from IronPdf.PdfDocument; the using PdfToSvg; directive brings it into scope.

How to Convert All Pages in a PDF to SVG?

Iterating the Pages collection converts every page. The PageNumber property (which is not the same as the collection index) provides a human-readable label for naming output files.

The code snippet loops over every page in the PDF and writes a separate SVG file for each one.

:path=/static-assets/pdf/content-code-examples/how-to/pdf-to-svg-all-pages.cs
using PdfToSvg;

using var pdf = PdfDocument.Open("multi-page-report.pdf");

Console.WriteLine($"Total pages: {pdf.Pages.Count}");

foreach (var page in pdf.Pages)
{
    string outputPath = $"page_{page.PageNumber}.svg";
    page.SaveAsSvg(outputPath);
    Console.WriteLine($"Saved: {outputPath}");
}
Imports PdfToSvg

Using pdf = PdfDocument.Open("multi-page-report.pdf")
    Console.WriteLine($"Total pages: {pdf.Pages.Count}")

    For Each page In pdf.Pages
        Dim outputPath As String = $"page_{page.PageNumber}.svg"
        page.SaveAsSvg(outputPath)
        Console.WriteLine($"Saved: {outputPath}")
    Next
End Using
$vbLabelText   $csharpLabel

Veuillez noterSVG does not support multi-page documents the way PDF does, so a 10-page PDF produces 10 individual SVG files.

For large documents, the async approach described in the next section avoids blocking the application thread during conversion.

Icon Quote related to How to Convert All Pages in a PDF to SVG?

Ma bibliothèque préférée de ce genre est IronPDF. Elle permet une manipulation rapide et efficace des fichiers PDF. Elle dispose également de nombreuses fonctionnalités précieuses, comme l'exportation au format PDF/A et la signature numérique des documents PDF.

Milan Jovanovic related to How to Convert All Pages in a PDF to SVG?

Milan Jovanovic

Microsoft MVP

Voir l'étude de cas
Icon Quote related to How to Convert All Pages in a PDF to SVG?

IronOCR signifie que nous pouvons économiser 40 000 $ par an grâce au traitement manuel, tout en améliorant la productivité et en libérant des ressources pour des tâches à fort impact. Je le recommande vivement.

Brent Matzelle related to How to Convert All Pages in a PDF to SVG?

Brent Matzelle

Directeur technique, OPYN

Voir l'étude de cas
Icon Quote related to How to Convert All Pages in a PDF to SVG?

Iron Suite joue un rôle crucial dans nos opérations. Ce sont des outils qui augmentent l'efficacité de l'entreprise, y compris la création de plans d'étage et l'amélioration de la gestion des stocks.

David Jones related to How to Convert All Pages in a PDF to SVG?

David Jones

Ingénieur logiciel principal, Agorus Build

Voir l'étude de cas

How to Use Async Methods for PDF-to-SVG Conversion?

The async variants, SaveAsSvgAsync() and ToSvgStringAsync(), keep I/O off the main thread. PdfDocument.OpenAsync() loads the PDF asynchronously as well. These methods are the right choice in ASP.NET Core handlers, background services, or any application with a responsive UI.

The example below opens the PDF and converts every page asynchronously, so the calling thread stays free while the work runs.

:path=/static-assets/pdf/content-code-examples/how-to/pdf-to-svg-async.cs
using PdfToSvg;

await using var pdf = await PdfDocument.OpenAsync("dashboard.pdf");

foreach (var page in pdf.Pages)
{
    await page.SaveAsSvgAsync($"dashboard_page_{page.PageNumber}.svg");
}

// Or get the SVG markup as a string
string firstPageSvg = await pdf.Pages[0].ToSvgStringAsync();
Imports PdfToSvg

Await Using pdf = Await PdfDocument.OpenAsync("dashboard.pdf")

    For Each page In pdf.Pages
        Await page.SaveAsSvgAsync($"dashboard_page_{page.PageNumber}.svg")
    Next

End Using

' Or get the SVG markup as a string
Dim firstPageSvg As String = Await pdf.Pages(0).ToSvgStringAsync()
$vbLabelText   $csharpLabel

How to Configure SVG Conversion Options?

SvgConversionOptions controls how the SVG output is generated. The most commonly used properties are:

  • IncludeAnnotations: set to true to render PDF annotation layers in the SVG output
  • IncludeLinks: set to true to carry PDF hyperlinks through as <a> elements in the SVG, keeping the output navigable in a browser
  • IncludeHiddenText: surfaces text that exists in the PDF content stream but is not visible, useful for accessibility or text-extraction pipelines
  • MinStrokeWidth: sets a floor (in SVG user units) for rendered strokes, preventing hairline paths from disappearing at normal viewing scales

The code below switches on annotations and links, sets a minimum stroke width, then exports every page using those options.

:path=/static-assets/pdf/content-code-examples/how-to/pdf-to-svg-options.cs
using PdfToSvg;

var options = new SvgConversionOptions
{
    IncludeAnnotations = true,
    IncludeLinks = true,
    IncludeHiddenText = false,
    MinStrokeWidth = 0.5
};

using var pdf = PdfDocument.Open("annotated-report.pdf");

foreach (var page in pdf.Pages)
{
    page.SaveAsSvg($"page_{page.PageNumber}.svg", options);
}
Imports PdfToSvg

Dim options As New SvgConversionOptions With {
    .IncludeAnnotations = True,
    .IncludeLinks = True,
    .IncludeHiddenText = False,
    .MinStrokeWidth = 0.5
}

Using pdf = PdfDocument.Open("annotated-report.pdf")
    For Each page In pdf.Pages
        page.SaveAsSvg($"page_{page.PageNumber}.svg", options)
    Next
End Using
$vbLabelText   $csharpLabel

Two additional properties control how text spacing is handled. CollapseSpaceEmbeddedFont and CollapseSpaceLocalFont set thresholds (as fractions of the font size) below which gaps between adjacent characters are collapsed into a single text run. Tighter values preserve more spacing fidelity; looser values produce smaller SVG files.

For advanced use cases, the FontResolver property accepts a custom resolver that maps PDF font references to local font resources, essential when the source document references fonts that are not embedded. The ImageResolver property controls how raster images within the PDF are handled in the SVG output: inline encoding produces a self-contained SVG file, while external path resolution keeps the SVG compact. The SvgConversionOptions API reference documents every configurable property.

How to Control PDF Layer Visibility in SVG Output?

A layered PDF exposes its layers through the OptionalContentGroups collection on PdfDocument. Each entry is an OptionalContentGroup that pairs a read-only Name (the layer label from the source document) with a get/set Visible flag. Setting Visible controls whether that layer is rendered during the SVG conversion, so a single PDF can produce different SVG variants without editing the file.

You do not need to know the layer names in advance. The collection reflects the layers actually present in the document, so you can enumerate it, read each Name, and switch off the ones you want to hide. ToString() returns the same value as Name, which is convenient for logging.

The example below lists every layer in the PDF, hides the one named Watermark, and exports the first page with that layer suppressed.

:path=/static-assets/pdf/content-code-examples/how-to/pdf-to-svg-layers.cs
using PdfToSvg;

using var pdf = PdfDocument.Open("technical-drawing.pdf");

// List the layers that actually exist in this PDF
foreach (var layer in pdf.OptionalContentGroups)
{
    Console.WriteLine($"{layer.Name} visible: {layer.Visible}");
}

// Hide the watermark layer; every other layer stays visible
foreach (var layer in pdf.OptionalContentGroups)
{
    if (layer.Name == "Watermark")
    {
        layer.Visible = false;
    }
}

// Visibility set on OptionalContentGroups is applied during conversion
pdf.Pages[0].SaveAsSvg("drawing-no-watermark.svg");
Imports PdfToSvg

Using pdf = PdfDocument.Open("technical-drawing.pdf")

    ' List the layers that actually exist in this PDF
    For Each layer In pdf.OptionalContentGroups
        Console.WriteLine($"{layer.Name} visible: {layer.Visible}")
    Next

    ' Hide the watermark layer; every other layer stays visible
    For Each layer In pdf.OptionalContentGroups
        If layer.Name = "Watermark" Then
            layer.Visible = False
        End If
    Next

    ' Visibility set on OptionalContentGroups is applied during conversion
    pdf.Pages(0).SaveAsSvg("drawing-no-watermark.svg")

End Using
$vbLabelText   $csharpLabel

A typical use case is a technical drawing, where annotation, dimension, or watermark layers need to be toggled independently. Because visibility is set per conversion, the same source PDF can produce several SVG variants with no changes to the file.

How to Open PDFs from Streams and with Passwords?

PdfDocument.Open() accepts a Stream in addition to a file path. The leaveOpen parameter (default false) controls whether the stream is closed when the document is disposed. Both path and stream overloads accept an OpenOptions object for configuration such as providing a password for encrypted documents, and a CancellationToken for cooperative cancellation in long-running workflows.

The snippet opens a PDF from a stream, saves its first page as SVG, then prints whether the file is encrypted, its title, and its page count.

:path=/static-assets/pdf/content-code-examples/how-to/pdf-to-svg-stream-and-password.cs
using PdfToSvg;

// Open from a stream (e.g., downloaded from a web API)
using var fileStream = File.OpenRead("document.pdf");
using var pdf = PdfDocument.Open(fileStream, leaveOpen: false);
pdf.Pages[0].SaveAsSvg("from-stream.svg");

// Check if a PDF is encrypted
Console.WriteLine($"Encrypted: {pdf.IsEncrypted}");

// Access document metadata
Console.WriteLine($"Title: {pdf.Info.Title}");
Console.WriteLine($"Pages: {pdf.Pages.Count}");
Imports PdfToSvg

' Open from a stream (e.g., downloaded from a web API)
Using fileStream = File.OpenRead("document.pdf")
    Using pdf = PdfDocument.Open(fileStream, leaveOpen:=False)
        pdf.Pages(0).SaveAsSvg("from-stream.svg")

        ' Check if a PDF is encrypted
        Console.WriteLine($"Encrypted: {pdf.IsEncrypted}")

        ' Access document metadata
        Console.WriteLine($"Title: {pdf.Info.Title}")
        Console.WriteLine($"Pages: {pdf.Pages.Count}")
    End Using
End Using
$vbLabelText   $csharpLabel

The Info property exposes document metadata including title, author, and creation date. The Permissions property reports what operations the PDF allows (printing, copying), and IsEncrypted indicates whether the file requires a password to open.

Next Steps

The PdfToSvg namespace converts PDF pages to SVG files, streams, or strings. It works per-page, with full control over annotations, links, text visibility, stroke width, and layer toggling. All methods have async variants for non-blocking workflows.

Explore the PdfPage API reference for the complete conversion method surface, the SvgConversionOptions reference for every configurable property, and the PdfDocument reference for open and load options. For the reverse direction (embedding SVG into a PDF), see the SVG to PDF how-to.

View licensing options starting at $749.

Questions Fréquemment Posées

What is the primary function of IronPDF in converting PDF to SVG?

IronPDF allows for the conversion of PDF pages to SVG format in C#. This conversion can be performed on a per-page basis, offering flexibility in handling PDF documents.

Can IronPDF handle annotations, links, and layers during PDF to SVG conversion?

Yes, IronPDF provides options to include annotations, links, and layers when converting PDF pages to SVG, ensuring that all important elements are preserved.

What output options does IronPDF offer for converting PDF to SVG?

IronPDF supports exporting converted SVGs to files, streams, or strings, allowing developers to choose the most appropriate format for their needs.

Is it possible to convert specific pages of a PDF to SVG using IronPDF?

Yes, with IronPDF, you can convert specific pages of a PDF document to SVG, enabling targeted conversion without processing the entire document.

How does IronPDF ensure the quality of SVG output from PDF conversion?

IronPDF ensures high-quality SVG output by accurately rendering PDF content, preserving layout, colors, and graphic elements during the conversion process.

Can IronPDF be used with other .NET languages besides C# for PDF to SVG conversion?

While this guide focuses on C#, IronPDF can be used with other .NET languages such as VB.NET, as it is a .NET library compatible with multiple languages.

Does IronPDF support batch conversion of PDF pages to SVG?

IronPDF can be used to automate the batch conversion of multiple PDF pages to SVG, streamlining workflows for large documents or multiple files.

What are the benefits of using IronPDF for converting PDF to SVG over other tools?

IronPDF offers comprehensive features such as per-page conversion, support for annotations and links, multiple output formats, and high-quality rendering, making it a robust choice compared to other tools.

Ahmad Sohail
Développeur Full Stack

Ahmad est un développeur full-stack avec une solide fondation en C#, Python et technologies web. Il a un profond intérêt pour la construction de solutions logicielles évolutives et aime explorer comment le design et la fonctionnalité se rencontrent dans des applications du monde réel.

<...
Lire la suite
Prêt à commencer ?
Nuget Téléchargements 20,296,129 | Version : 2026.7 vient de sortir
Still Scrolling Icon

Vous faites encore défiler ?

Vous voulez une preuve rapidement ? PM > Install-Package IronPdf
exécuter un échantillon Regardez votre code HTML se transformer en PDF.