Table of Contents
Installed via NuGet
PM> Install-Package Spire.PDF
Related Links
SVG (Scalable Vector Graphics) is an image file format used for rendering two-dimensional images on the web. Comparing with other image file formats, SVG has many advantages such as supporting interactivity and animation, allowing users to search, index, script, and compress/enlarge images without losing quality. Occasionally, you may need to convert PDF files to SVG file format, and this article will demonstrate how to accomplish this task using Spire.PDF for .NET.
- Convert a PDF File to SVG in C#/VB.NET
- Convert Selected PDF Pages to SVG in C#/VB.NET
- Convert a PDF File to SVG with Custom Width and Height in C#/VB.NET
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Convert a PDF File to SVG in C#/VB.NET
Spire.PDF for .NET offers the PdfDocument.SaveToFile(String, FileFormat) method to convert each page in a PDF file to a single SVG file. The detailed steps are as follows.
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.LoadFromFile() method.
- Convert the PDF file to SVG using PdfDocument.SaveToFile(String, FileFormat) method.
- C#
- VB.NET
using Spire.Pdf; namespace ConvertPDFtoSVG { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument document = new PdfDocument(); //Load a sample PDF file document.LoadFromFile("input.pdf"); //Convert PDF to SVG document.SaveToFile("PDFtoSVG.svg", FileFormat.SVG); } } }
Convert Selected PDF Pages to SVG in C#/VB.NET
The PdfDocument.SaveToFile(String, Int32, Int32, FileFormat) method allows you to convert the specified pages in a PDF file to SVG files. The detailed steps are as follows.
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.LoadFromFile() method.
- Convert selected PDF pages to SVG using PdfDocument.SaveToFile(String, Int32, Int32, FileFormat) method.
- C#
- VB.NET
using Spire.Pdf; namespace PDFPagetoSVG { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Load a sample PDF file doc.LoadFromFile("input.pdf"); //Convert selected PDF pages to SVG doc.SaveToFile("PDFPagetoSVG.svg", 1, 2, FileFormat.SVG); } } }
Convert a PDF File to SVG with Custom Width and Height in C#/VB.NET
The PdfConvertOptions.SetPdfToSvgOptions() method offered by Spire.PDF for .NET allows you to specify the width and height of output SVG file. The detailed steps are as follows.
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.LoadFromFile() method.
- Set PDF convert options using PdfDocument.ConvertOptions property.
- Specify the width and height of output SVG file using PdfConvertOptions.SetPdfToSvgOptions() method.
- Convert the PDF file to SVG using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf; namespace PDFtoSVG { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument document = new PdfDocument(); //Load a sample PDF file document.LoadFromFile("input.pdf"); //Specify the width and height of output SVG file document.ConvertOptions.SetPdfToSvgOptions(800f, 1200f); //Convert PDF to SVG document.SaveToFile("result.svg", FileFormat.SVG); } } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.