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 NuGet을 사용하여 설치하세요

PM >  Install-Package IronPdf

빠른 설치를 원하시면 NuGet 에서 https://www.nuget.org/packages/IronPdf를 검색해 보세요. 1천만 건 이상의 다운로드를 기록하며 C#을 이용한 PDF 개발 방식을 혁신하고 있습니다. DLL 파일 이나 윈도우 설치 프로그램을 다운로드할 수도 있습니다.

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

  1. NuGet 패키지 관리자를 사용하여 https://www.nuget.org/packages/IronPdf 설치하기

    PM > Install-Package IronPdf
  2. 다음 코드 조각을 복사하여 실행하세요.

    using PdfToSvg;
    
    using var pdf = PdfDocument.Open("report.pdf");
    pdf.Pages[0].SaveAsSvg("page-one.svg");
  3. 실제 운영 환경에서 테스트할 수 있도록 배포하세요.

    무료 체험판으로 오늘 프로젝트에서 IronPDF 사용 시작하기

    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.

참고해 주세요PdfToSvg.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

참고해 주세요SVG 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?

이 종류의 라이브러리 중 가장 좋아하는 것은 IronPDF입니다. PDF 파일을 빠르고 효율적으로 조작할 수 있습니다. 또한 PDF/A 형식으로 내보내기 및 PDF 문서의 디지털 서명과 같은 많은 유용한 기능을 가지고 있습니다.

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

Milan Jovanovic

마이크로소프트 MVP

사례 연구 보기
Icon Quote related to How to Convert All Pages in a PDF to SVG?

IronOCR 덕분에 연간 $40,000를 수동 프로세싱에서 절약하고 생산성을 높이며 고부가가치 작업에 자원을 활용할 수 있습니다. 강력히 추천합니다.

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

브렌트 마첼

최고 기술 책임자, OPYN

사례 연구 보기
Icon Quote related to How to Convert All Pages in a PDF to SVG?

IronSuite는 우리의 운영에서 중요한 역할을 합니다. 이것들은 사업 전반에 걸쳐 효율성을 높이는 도구로, 평면도 생성 및 재고 관리 개선을 포함합니다.

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

데이비드 존스

리드 소프트웨어 엔지니어, Agorus Build

사례 연구 보기

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.

자주 묻는 질문

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.

아흐마드 소하일
풀스택 개발자

아흐마드는 C#, Python 및 웹 기술에 탄탄한 기반을 갖춘 풀스택 개발자입니다. 그는 확장 가능한 소프트웨어 솔루션 구축에 깊은 관심을 가지고 있으며, 실제 응용 프로그램에서 디자인과 기능이 어떻게 조화를 이루는지 탐구하는 것을 즐깁니다.

Iron Software 팀에 합류하기 전, 아흐마드는 자동화 프로젝트와 API 통합 업무를 담당하며 성능 향상과 개발자 경험 개선에 주력했습니다.

그는 여가 시간에 UI/UX 아이디어를 실험하고, 오픈 소스 도구에 기여하며, 복잡한 주제를 더 쉽게 이해할 수 있도록 기술 문서를 작성하는 데 몰두하기도 합니다.

시작할 준비 되셨나요?
Nuget 다운로드 20,296,129 | 버전: 2026.7 방금 출시
Still Scrolling Icon

아직도 스크롤하고 계신가요?

빠른 증거를 원하시나요? PM > Install-Package IronPdf
샘플을 실행하세요 HTML이 PDF로 변환되는 것을 지켜보세요.