Spire.Cloud.PDF 转换 PDF 为 Word 和图片

 

Spire.Cloud.PDF提供的PdfConvertApi接口用于将PDF文档保存为DOC、DOCX、HTML、PCL、PS、SVG、XPS和PNG格式文档。本文以转DOC和PNG为例,介绍如何使用该接口将PDF文档转换为其他格式。

步骤一:创建.NET应用程序,通过NuGet搜索安装Spire.Cloud.Sdk到您的.NET项目,详细步骤可参考这篇文章

步骤二:通过冰蓝云官网(https://cloud.e-iceblue.cn/)注册账号并登陆,在“我的应用”版块创建应用程序,获得App ID及App Key。

步骤三:上传PDF文档至冰蓝云官网的“文档管理”版块。为了便于文档管理,您也可以先创建文件夹“input”和“output”,然后将需要转换的PDF文档上传至input文件夹,output文件夹用于存放生成的文档。本教程将示例文档(sample.pdf)上传到了input文件夹下。

Spire.Cloud.PDF 转换 PDF 为 Word 和图片

步骤四:在.NET程序中编写测试类操作input文件夹下的文档。

示例1、转换PDF为Word

using System;
using Spire.Cloud.Pdf.Sdk.Api;
using Spire.Cloud.Pdf.Sdk.Client;

namespace ConvertPdfToWord
{
    class Program
    {
        static String appId = "App ID";
        static String appKey = "App Key";
        static String baseUrl = "https://api.e-iceblue.cn";

        //配置App ID和App Key
        static Configuration pdfConfiguration = new Configuration(appId, appKey, baseUrl);

        //初始化PdfConvertApi对象
        static PdfConvertApi pdfConvertApi = new PdfConvertApi(pdfConfiguration);
        static void Main(string[] args)
        {
            //指定源文档名称
            string name = "sample.pdf";

            //指定转换后文档的名称和存放路径
            string dstpath = "output/ToDoc.doc";

            //指定转换后的文档格式
            string format = "Doc";

            //指定源文档存放文件夹
            string folder = "input";

            //指定存储空间,使用冰蓝云默认存储空间,设置为null
            string storage = null;

            //指定源文档的打开密码,无密码则为null
            string password = null;

            //调用Convert方法将PDF转换为Doc格式并保存到指定路径
            pdfConvertApi.Convert(name, dstpath, format, folder, storage, password);
        }
    }
}

示例2、转换PDF为图片

using System;
using Spire.Cloud.Pdf.Sdk.Api;
using Spire.Cloud.Pdf.Sdk.Client;

namespace ConvertPdfToPng
{
    class Program
    {
        static String appId = "App ID";
        static String appKey = "App Key";
        static String baseUrl = "https://api.e-iceblue.cn";

        //配置App ID和App Key
        static Configuration pdfConfiguration = new Configuration(appId, appKey, baseUrl);

        //初始化PdfConvertApi对象
        static PdfConvertApi pdfConvertApi = new PdfConvertApi(pdfConfiguration);

        static void Main(string[] args)
        {
            //指定源文档名称
            string name = "sample.pdf";

            //指定生成文档存放路径
            string destFilepath = "output/";

            //指定图片分辨率
            int dx = 300;
            int dy = 300;

            //指定源文档存放文件夹
            string folder = "input";

            //指定存储空间,使用冰蓝云默认存储空间,设置为null
            string storage = null;

            //指定源文档打开密码,无密码则为null
            string password = null;

            //调用ConvertToPng方法将PDF转为Png格式,并保存到指定路径
            pdfConvertApi.ConvertToPng(name, destFilepath, dx, dy, folder, storage, password);
        }
    }
}