IRONSOFTWAREHOME

How to Convert PDF to SVG in C#

Ahmad Sohail
Ahmad Sohail
Updated: 2026年7月24日

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.

NuGetNuGetでインストール

PM > Install-Package IronPdf

Install IronPDF by running the command above in the NuGet Package Manager Console, or search for the package in the NuGet Package Manager.

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

  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2このコード スニペットをコピーして実行します。

    using PdfToSvg;
    
    using var pdf = PdfDocument.Open("report.pdf");
    pdf.Pages[0].SaveAsSvg("page-one.svg");
    C#
  3. 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.

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);
C#

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.

When Is PDF to SVG the Right Choice?

SVG is the better output when a page will be zoomed, embedded in a web layout, or restyled after conversion: text stays selectable and searchable, and paths stay editable in vector tools. For scanned or photographic pages there is no vector content to preserve, so a raster export is smaller and loses nothing.

How to Convert All Pages in a PDF to SVG?

The Pages collection is zero-indexed, so adding one to the loop index gives a human-readable page number for each output file.

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}");
}
C#
ご注意: 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.

私のお気に入りのこの種のライブラリはIronPDFです。PDFファイルの迅速で効率的な操作が可能です。また、PDF/A形式へのエクスポートやPDF文書へのデジタル署名といった多くの貴重な機能も備えています。

Milan Jovanovic

Microsoft MVP

ケーススタディを見る

IronOCRのおかげで私たちは年間$40,000を手作業の処理から節約し、生産性を向上させ、高影響のタスクにリソースを充てることができます。非常にお勧めします。

Brent Matzelle

最高技術責任者, OPYN

ケーススタディを見る

IronSuiteは私たちの業務において重要な役割を果たしています。これらは、フロアプランの作成や在庫管理の改善を含め、ビジネス全体の効率を向上させるツールです。

David Jones

リードソフトウェアエンジニア、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.

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();
C#

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.

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);
}
C#

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.

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

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.

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}");
C#

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 $999.

よくある質問

What is the purpose of converting PDF files to SVG format?

Converting PDF files to SVG format allows for embedding document content in web pages, generating resolution-independent previews, and extracting vector graphics from reports, invoices, or technical drawings. SVG is scalable and does not pixelate, making it ideal for web and design applications.

How can IronPDF's PdfToSvg be utilized for a PDF to SVG conversion?

IronPDF's PdfToSvg namespace provides a dedicated API for converting PDF pages to SVG format. You can open a PDF with PdfDocument.Open(), access the individual pages through the Pages collection, and then call SaveAsSvg() or ToSvgString() on each PdfPage to produce SVG output.

Can PDF pages be converted to SVG asynchronously using IronPDF?

Yes, IronPDF supports asynchronous PDF to SVG conversions. You can use the SaveAsSvgAsync() and ToSvgStringAsync() methods to keep the I/O operations off the main thread, which is beneficial in responsive applications.

What are SvgConversionOptions in IronPDF?

SvgConversionOptions in IronPDF control how the SVG output is generated. Options include whether to include annotations, links, and hidden text in the output, as well as setting minimum stroke width. These options allow for customization of the SVG conversion process.

Is it possible to control layer visibility when converting PDF to SVG using IronPDF?

Yes, IronPDF allows control over PDF layer visibility using the OptionalContentGroups collection on PdfDocument. You can toggle visibility for specific layers, which determines whether they are rendered during the SVG conversion.

How does IronPDF handle encrypted PDF files for conversion to SVG?

IronPDF can open encrypted PDF files using the OpenOptions object, which includes providing a password. This allows encrypted PDFs to be converted into SVG after authentication.

What are the benefits of using SVG format for PDFs in web applications?

SVG format is beneficial for web applications because it maintains high-quality, scalable graphics without pixelation, supports selectable and searchable text, and allows for style modifications using CSS or scripting.

Can IronPDF convert all pages of a PDF into individual SVG files?

Yes, IronPDF can convert all pages of a PDF into individual SVG files. By iterating through the Pages collection, you can save each page as a separate SVG file, which is useful for multi-page PDFs.

What are the minimal steps to start converting a PDF to SVG using IronPDF?

To convert a PDF to SVG using IronPDF, you need to install IronPDF via NuGet, open a PDF with PdfDocument.Open() from the PdfToSvg namespace, and call SaveAsSvg() on any page to write the SVG file.

Does IronPDF support opening PDFs from streams for conversion purposes?

Yes, IronPDF supports opening PDFs from streams. You can use PdfDocument.Open() with a Stream input, making it versatile for scenarios where PDFs are not stored as files but are being streamed from other sources.

Ahmad Sohail
フルスタックデベロッパー

Ahmadは、C#、Python、およびウェブ技術に強い基盤を持つフルスタック開発者です。彼はスケーラブルなソフトウェアソリューションの構築に深い関心を持ち、デザインと機能が実際のアプリケーションでどのように融合するかを探求することを楽しんでいます。

...
詳しく読む

準備はできましたか?

Nuget Downloads 20,809,720バージョン:2026.9リリースされたばかり

あなたの無料30日間の試用キーをすぐに入手。
クレジットカードやアカウントの作成は不要です。
PDF用C# NuGetライブラリ
NuGetでインストール

バージョン: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. ソリューションエクスプローラーで参照を右クリックし、NuGetパッケージを管理を選択
  2. ブラウズを選択し、"IronPDF"を検索
  3. パッケージを選択してインストール
C# PDF DLL
DLLをダウンロード

バージョン: 2026.9

またはここからWindowsインストーラーをダウンロードする。

  1. IronPDFを~/Libsなどの場所に解凍し、ソリューションディレクトリ内に配置する
  2. Visual Studioソリューションエクスプローラーで参照を右クリックし、"IronPDF.dll"をブラウズして選択

ライセンスは$999から

Key in blue circle

無料の30日間トライアルキーをすぐに入手してください。

Your trial license will be sent to your email address

制限なし。100% ロック解除済み。クレジットカード不要。

bullet_checkedクレジットカードやアカウントの作成は不要です。制限なし。100% ロック解除済み。クレジットカード不要。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
無料のライブデモを予約する
Booking Badge

世界中の数百万人のエンジニアから信頼されています。

ライセンスはより安く
義務のない相談を受ける
下記のフォームを記入するか、sales@ironsoftware.comにメールしてください。
あなたの詳細は常に守秘されます。
世界中の数百万人のエンジニアから信頼されています。
ライセンスはより安く
あなたの無料30日間の試用キーをすぐに入手。
クレジットカードやアカウントの作成は不要です。