C# 将PDF转为SVG的3种状况

  PDF格式的文档普遍用于各类办公场所,在工做中不免会有将PDF文档转换为其余文档格式的须要。在本篇文档中,将介绍PDF转为SVG的方法。根据不一样的转换需求,这里分三种状况进行讲述,即转PDF全部页为SVG、转PDF指定页为SVG和转PDF到指定高度、宽度的SVG。以上三种状况,下面将做详细介绍。网络

  使用工具:Spire.PDF for .NETsvg

  提示:使用该组件须要先下载安装,在项目程序中注意须添加引用Spire.PDF.dll文件(以下所示)工具

C# 将PDF转为SVG的3种状况

  原PDF文档:spa

C# 将PDF转为SVG的3种状况

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

  }

  }

  }

  复制代码

  调试运行该项目,生成文档:

C# 将PDF转为SVG的3种状况
C# 将PDF转为SVG的3种状况

  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文档

  转换后的文档:

C# 将PDF转为SVG的3种状况

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

  }

  }

  }

  复制代码

  (编辑:雷林鹏 来源:网络)

相关文章
相关标签/搜索