Three cases of converting PDF to SVG

Pdf documents are widely used in all kinds of office places. It is inevitable to convert PDF documents into other document formats. In this document, you will see how PDF can be converted to SVG. According to different conversion requirements, there are three situations to describe, that is, to convert all pages of PDF to SVG, to convert specified pages of PDF to SVG and to convert PDF to SVG of specified height and width. The above three situations will be described in detail below.

Use tools: Spire.PDF for .NET

Tip: to use this component, you need to download and install it first. In the project program, you need to add the reference Spire.PDF.dll file (as shown below)

Original PDF document:

1. Convert all PDF pages to SVG

using Spire.Pdf;

namespace PDFtoSVG_PDF
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a new one PdfDocument Class object, loading sample,Save as SVG Format file
            PdfDocument document = new PdfDocument();
            document.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");
            document.SaveToFile("output.svg", FileFormat.SVG);
        }
    }
}

Debug and run the project to generate documents:

2. Convert the specified PDF page to SVG

using Spire.Pdf;

namespace ConvertPDFPagetoSVG_PDF
{
    class Program
    {
        static void Main(string[] args)
        {
            //item base  PdfDocument Class object
            PdfDocument doc = new PdfDocument();
            //Load PDF file
            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");
            //Call method SaveToFile(string filename, int startIndex, int endIndex, FileFormat )take PDF Specify page to save as SVG format
            doc.SaveToFile("Result.svg", 1, 2, FileFormat.SVG);
        }
    }
}

After debugging the running program, you can view the SVG document of the successful conversion

Converted document:

3. Convert PDF to SVG of specified width and height

using Spire.Pdf;

namespace PDFtoSVG1_PDF
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument Class object, and load PDF file
            PdfDocument document = new PdfDocument();
            document.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");
            //Call method SetPdfToSvgOptions()Specify conversion SVG Width and height of
            document.ConvertOptions.SetPdfToSvgOptions(700f, 1000f);
            //Save to a file, name the document, and format the save
            document.SaveToFile("result.svg", FileFormat.SVG);
        }
    }
}

 

The above content is the introduction of three ways to convert PDF to SVG, and the corresponding conversion methods can be selected according to different office needs.

If you like, you are welcome to reprint (please indicate the source of Reprint)

Tags: C#

Posted on Wed, 29 Apr 2020 23:24:10 -0700 by fredyap1234