C# 将PDF转为Word、Html、XPS、SVG、PCL、PS

2025-10-21 14:26:55

1、dll文件获取及导入。

方法1. 通过e-iceblue中国官网进入在线编辑,选择本地下载SDK文件包。(须注册并登录)

下载后,解压文件,将Spire.Cloud.Pdf.Sdk.dll文件及其他三个dll添加引用至VS程序;

C# 将PDF转为Word、Html、XPS、SVG、PCL、PS

2、方法2. 在程序中通过Nuget搜索下载,直接导入所有dll。

导入效果如下如所示:

C# 将PDF转为Word、Html、XPS、SVG、PCL、PS

1、App ID及Key获取。在云端创建账号,并在“我的应用”板块中创建应用以获得App ID及App Key。

C# 将PDF转为Word、Html、XPS、SVG、PCL、PS

1、源文档上传。在“文档管理”板块,上传源文档。这里可以建文件夹,将文档存放在文件夹下。不建文件夹时,源文档及结果文档直接保存在根目录。本文示例中,建了两个文件夹,分别用于存放源文档及结果文档。(云平台提供免费1 万次调用次数和 2G 文档内存)

1、PDF 转Word(docx/doc):

using System;

using Spire.Cloud.Pdf.Sdk.Client;

using Spire.Cloud.Pdf.Sdk.Api;

using System.IO;

 

namespace PDFToWord

{

    class PDFToDocx

    {

        static String appId = "App ID";

        static String appKey = "App Key";

        static void Main(string[] args)

        {

            //配置账号信息

            Configuration pdfConfiguration = new Configuration(appId, appKey);

            PdfConvertApi pdfConverterApi = new PdfConvertApi(pdfConfiguration);

            string name = "sample.pdf";//源文档       

            string folder = "input";//设置源文档所在文件夹(如果源文档在根目录下,不在文件夹中,可设置为null)

            string destFilePath = "pdfconversion/PDFToDocx.docx";//设置转换后的目标文档路径(文档放置在pdfconversion文件夹下)

            string destFilePath2 = "pdfconversion/PDFToDoc.doc";

            string password = null;//设置文档密码(如果文档没有密码则设置成null)

            //调用方法转为Word文档格式

            pdfConverterApi.ConvertPdfInStorageToDocx(name, destFilePath, folder, password);

            pdfConverterApi.ConvertPdfInStorageToDoc(name, destFilePath2, folder, password);

        }

    }

}

2、 PDF转Html:

using System;

using Spire.Cloud.Pdf.Sdk.Client;

using Spire.Cloud.Pdf.Sdk.Api;

 

namespace PDFToHTML

{

    class Program

    {

        static String appId = "App ID";

        static String appKey = "App Key";

        static void Main(string[] args)

        {

            //配置账号信息

            Configuration pdfConfiguration = new Configuration(appId, appKey);

            PdfConvertApi pdfConvertApi = new PdfConvertApi(pdfConfiguration);

            string name = "sample.pdf";//源文档         

            string folder = "input";//设置源文档所在文件夹(如果源文档在根目录下,不在文件夹中,可设置为null)

            string destFilePath = "pdfconversion/PDFToHtml.html";//设置转换后的目标文档路径(文档放置在pdfconversion文件夹下)

            string password = null;//设置文档密码(如果文档没有密码则设置成null)

            //调用方法转换为HTML格式

            pdfConvertApi.ConvertPdfInStorageToHtml(name,destFilePath,folder,password);

        }

    }

}

3、PDF转XPS:

using System;

using Spire.Cloud.Pdf.Sdk.Client;

using Spire.Cloud.Pdf.Sdk.Api;

 

namespace PDFToXPS

{

    class Program

    {

        static String appId = "App ID";

        static String appKey = "App Key";

        static void Main(string[] args)

        {

            //配置账号信息

            Configuration pdfConfiguration = new Configuration(appId, appKey);

            PdfConvertApi pdfConvertapi = new PdfConvertApi(pdfConfiguration);

            string name = "sample.pdf";//源文档

            string folder = "input";//设置源文档所在文件夹(如果源文档在根目录下,不在文件夹中,可设置为null)

            string destFilePath = "pdfconversion/PDFToXPS.xps";//设置转换后的目标文档路径(文档放置在pdfconversion文件夹下)

            string password = null;//设置文档密码(如果文档没有密码则设置成null)

            //调用方法转为XPS

            pdfConvertapi.ConvertPdfInStorageToXps(name, destFilePath, folder, password);

        }

    }

}

4、PDF转SVG:

using System;

using Spire.Cloud.Pdf.Sdk.Client;

using Spire.Cloud.Pdf.Sdk.Api;

 

namespace PDFToSvg

{

    class Program

    {

        static String appId = "App ID";

        static String appKey = "App Key";

        static void Main(string[] args)

        {

            //配置账号信息

            Configuration pdfConfiguration = new Configuration(appId, appKey);

            PdfConvertApi pdfConvertapi = new PdfConvertApi(pdfConfiguration);

            string name = "sample.pdf";//源文档

            string folder = "input";//设置源文档所在文件夹(如果源文档在根目录下,不在文件夹中,可设置为null)

            string destFilePath = "pdfconversion/PDFToSvg.svg";//设置转换后的目标文档路径(文档放置在pdfconversion文件夹下)

            string password = null;//设置文档密码(如果文档没有密码则设置成null)

            //调用方法转为SVG

            pdfConvertapi.ConvertPdfInStorageToSvg(name, destFilePath, folder, password);

        }

    }

}

注:这里转为svg是将原PDF文档中的每一页单独转换为一个svg文档,如果原PDF文档包含多页,转换后默认生成一个文件夹,将生成的每一页svg放在这个文件夹下。

5、PDF转PCL:

using System;

using Spire.Cloud.Pdf.Sdk.Client;

using Spire.Cloud.Pdf.Sdk.Api;

 

namespace PDFToPcl

{

    class Program

    {

        static String appId = "App ID";

        static String appKey = "App Key";

        static void Main(string[] args)

        {

            //配置账号信息

            Configuration pdfConfiguration = new Configuration(appId, appKey);

            PdfConvertApi pdfConvertApi = new PdfConvertApi(pdfConfiguration);

            string name = "sample.pdf";//源文档         

            string folder = "input";//设置源文档所在文件夹(如果源文档在根目录下,不在文件夹中,可设置为null)

            string destFilePath = "pdfconversion/PDFToPcl.pcl";//设置转换后的目标文档路径(文档放置在pdfconversion文件夹下)

            string password = null;//设置文档密码(如果文档没有密码则设置成null)

            //调用方法转换为Pcl格式

            pdfConvertApi.ConvertPdfInStorageToPcl(name, destFilePath, folder, password);

        }

    }

}

6、PDF转PS:

using System;

using Spire.Cloud.Pdf.Sdk.Client;

using Spire.Cloud.Pdf.Sdk.Api;

namespace PDFToPs

{

    class Program

    {

        static String appId = "App ID";

        static String appKey = "App Key";

        static void Main(string[] args)

        {

            //配置账号信息

            Configuration pdfConfiguration = new Configuration(appId, appKey);

            PdfConvertApi pdfConvertapi = new PdfConvertApi(pdfConfiguration);

            string name = "sample.pdf";//源文档

            string folder = "input";//设置源文档所在文件夹(如果源文档在根目录下,不在文件夹中,可设置为null)

            string destFilePath = "pdfconversion/PDFToPs.ps";//设置转换后的目标文档路径(文档放置在pdfconversion文件夹下)

            string password = null;//设置文档密码(如果文档没有密码则设置成null)

            //调用方法转为PS

            pdfConvertapi.ConvertPdfInStorageToPs(name, destFilePath, folder, password);

        }

    }

}

7、文档格式转换效果:

C# 将PDF转为Word、Html、XPS、SVG、PCL、PS

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢