How to Convert PDF to SVG in C#
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.
The example below opens a PDF and saves its first page as an SVG file.
-
1Install IronPDF with NuGet Package Manager
-
2Copy and run this code snippet.
using PdfToSvg; using var pdf = PdfDocument.Open("report.pdf"); pdf.Pages[0].SaveAsSvg("page-one.svg");C# -
3Deploy to test on your live environment
Start using IronPDF in your project today with a free trial
Minimal Workflow (3 Steps)
- Install IronPDF via NuGet:
Install-Package IronPdf - Open a PDF with
PdfDocument.Open()from thePdfToSvgnamespace - 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 orStream.SaveAsSvgAsync(): the non-blocking variant ofSaveAsSvg().ToSvgString(): returns the SVG markup as astring, useful when the output feeds a template engine, an HTTP response, or a downstream pipeline.ToSvgStringAsync(): the non-blocking variant ofToSvgString().
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);
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}");
}
For large documents, the async approach described in the next section avoids blocking the application thread during conversion.
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.
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();
How to Configure SVG Conversion Options?
SvgConversionOptions controls how the SVG output is generated. The most commonly used properties are:
IncludeAnnotations: set totrueto render PDF annotation layers in the SVG outputIncludeLinks: set totrueto carry PDF hyperlinks through as<a>elements in the SVG, keeping the output navigable in a browserIncludeHiddenText: surfaces text that exists in the PDF content stream but is not visible, useful for accessibility or text-extraction pipelinesMinStrokeWidth: 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);
}
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");
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}");
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.
Frequently Asked Questions
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 is a full-stack developer with a strong foundation in C#, Python, and web technologies. He has a deep interest in building scalable software solutions and enjoys exploring how design and functionality meet in real-world applications.