• C# 将PDF转为SVG的3种情况


      PDF格式的文档广泛用于各种办公场所,在工作中难免会有将PDF文档转换为其他文档格式的需要。在本篇文档中,将介绍PDF转为SVG的方法。根据不同的转换需求,这里分三种情况进行讲述,即转PDF所有页为SVG、转PDF指定页为SVG和转PDF到指定高度、宽度的SVG。以上三种情况,下面将作详细介绍。

      使用工具:Spire.PDF for .NET

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

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

      原PDF文档:

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

      1.将PDF所有页转为SVG

      using Spire.Pdf;

      namespace PDFtoSVG_PDF

      {

      class Program

      {

      static void Main(string[] args)

      {

      //新建一个PdfDocument类对象,加载sample,保存为SVG格式的文件

      PdfDocument document = new PdfDocument();

      document.LoadFromFile(@"C:UsersAdministratorDesktopsample.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:UsersAdministratorDesktopsample.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:UsersAdministratorDesktopsample.pdf");

      //调用方法SetPdfToSvgOptions()指定转换SVG的宽度和高度

      document.ConvertOptions.SetPdfToSvgOptions(700f, 1000f);

      //保存到文件,命名文档,并设置保存格式

      document.SaveToFile("result.svg", FileFormat.SVG);

      }

      }

      }

      复制代码

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

  • 相关阅读:
    看过的代码
    ScipyLectures-simple学习笔记
    机器学习1一个月2017/11/24-2017/12/24
    机器学习课程 matlab 练习
    win7 win8 快捷键直接调出任务管理器
    java 关于getProperty()方法中反斜杠问题
    把myeclipse中html/jsp文件的视图调到只看代码
    Win7 server2008 共享文件夹 不输入网络密码
    别用visual editor了,用WindowBuilder
    visual editor ve1.5下载
  • 原文地址:https://www.cnblogs.com/pengpeng1208/p/9339820.html
Copyright © 2020-2023  润新知