PDF格式的文檔普遍用於各類辦公場所,在工做中不免會有將PDF文檔轉換爲其餘文檔格式的須要。在本篇文檔中,將介紹PDF轉爲SVG的方法。根據不一樣的轉換需求,這裏分三種狀況進行講述,即轉PDF全部頁爲SVG、轉PDF指定頁爲SVG和轉PDF到指定高度、寬度的SVG。以上三種狀況,下面將做詳細介紹。網絡
使用工具:Spire.PDF for .NETsvg
提示:使用該組件須要先下載安裝,在項目程序中注意須添加引用Spire.PDF.dll文件(以下所示)工具
原PDF文檔:spa
1.將PDF全部頁轉爲SVG調試
using Spire.Pdf;orm
namespace PDFtoSVG_PDF對象
{文檔
class Programget
{string
static void Main(string[] args)
{
//新建一個PdfDocument類對象,加載sample,保存爲SVG格式的文件
PdfDocument document = new PdfDocument();
document.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");
document.SaveToFile("output.svg", FileFormat.SVG);
}
}
}
複製代碼
調試運行該項目,生成文檔:
2.將指定PDF頁轉爲SVG
using Spire.Pdf;
namespace ConvertPDFPagetoSVG_PDF
{
class Program
{
static void Main(string[] args)
{
//實例化一個PdfDocument類對象
PdfDocument doc = new PdfDocument();
//加載PDF文件
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");
//調用方法SaveToFile(string filename, int startIndex, int endIndex, FileFormat )將PDF指定頁保存爲SVG格式
doc.SaveToFile("Result.svg", 1, 2, FileFormat.SVG);
}
}
}
複製代碼
調試運行程序後,可查當作功轉換的SVG文檔
轉換後的文檔:
3.PDF轉指定寬度、高度的SVG
using Spire.Pdf;
namespace PDFtoSVG1_PDF
{
class Program
{
static void Main(string[] args)
{
//建立一個PdfDocument類對象,並加載PDF文件
PdfDocument document = new PdfDocument();
document.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");
//調用方法SetPdfToSvgOptions()指定轉換SVG的寬度和高度
document.ConvertOptions.SetPdfToSvgOptions(700f, 1000f);
//保存到文件,命名文檔,並設置保存格式
document.SaveToFile("result.svg", FileFormat.SVG);
}
}
}
複製代碼
(編輯:雷林鵬 來源:網絡)