C# 将Word转为PDF、XPS、Epub、RTF(基于Spire.Cloud.Word.SDK)
本文介绍通过调用Spire.Cloud.Word.SDK提供的ConvertApi接口将Word转换为PDF、XPS、Epub、RTF以及将Docx转为Doc格式等。调用接口方法及步骤参考以下内容:
步骤一:dll文件获取及导入。通过官网本地下载SDK文件包。(须在e-iceblue中国官网在线编辑板块中注册账号并登录)

下载后,解压文件,将Spire.Cloud.Word.Sdk.dll文件及其他三个dll添加引用至VS程序;或者在程序中通过Nuget搜索下载,直接导入所有dll。dll引用结果如下图所示:

步骤二:App ID及Key获取。在“我的应用”板块中创建应用以获得App ID及App Key。

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

C# 代码示例
1. Word转PDF
using System;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Api; namespace WordToPDF
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static void Main(string[] args)
{
//配置App ID和App Key
Configuration configuration = new Configuration(appId, appKey); //初始化ConvertApi对象
ConvertApi convertApi = new ConvertApi(configuration); string name = "Sample.docx";//源文档
string format = "pdf";//转换的目标文档格式
string password = null;//源文档
string folder = "input";//源文档所在文件夹,如果没有文件夹则为null
string storage = null;//使用冰蓝云配置的2G空间存贮文档,可设置为null
string destFilePath = "output/WordToPDF.pdf";//结果文档路径(结果文档保存在output文件夹下) //调用方法将Word转为PDF
convertApi.ConvertDocument(name, format, password, folder, storage, destFilePath);
}
}
}
2. Word转XPS
using System;
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client; namespace WordToXPS
{
class Program
{
static String appId = "App ID";
static String appKey = "APP Key";
static void Main(string[] args)
{
//配置App ID和App Key
Configuration configuration = new Configuration(appId, appKey); //初始化ConvertApi对象
ConvertApi convertApi = new ConvertApi(configuration); string name = "Sample.docx"; //源文档
string format = "xps";//转换的目标文档格式
string password = null;//源文档密码
string folder = "input";//源文档的文件夹,如果没有文件夹则为null
string storage = null;//使用冰蓝云配置的2G空间存贮文档,可设置为null
string destFilePath = "output/WordToXPS.xps";//结果文档路径及名称(结果文档保存在output文件夹下) //调用方法将Word转为XPS
convertApi.ConvertDocument(name, format, password, folder, storage, destFilePath);
}
}
}
3. Word转Epub
using System;
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client; namespace WordToEpub
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static void Main(string[] args)
{
//配置App ID和App Key
Configuration configuration = new Configuration(appId, appKey); //初始化ConvertApi对象
ConvertApi convertApi = new ConvertApi(configuration); string name = "Sample.docx"; //源文档
string format = "epub";//转换的目标文档格式
string password = null;//源文档密码
string folder = "input";//源文档的文件夹,如果没有文件夹则为null
string storage = null;//使用冰蓝云配置的2G空间存贮文档,可设置为null
string destFilePath = "output/WordToEpub.epub";//结果文档路径及名称(结果文档保存在output文件夹下) //调用方法将Word转为Epub
convertApi.ConvertDocument(name, format, password, folder, storage, destFilePath);
}
}
}
4. Word转RTF
using System;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Api; namespace WordToRTF
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static void Main(string[] args)
{
//配置App ID和App Key
Configuration configuration = new Configuration(appId, appKey); //初始化ConvertApi对象
ConvertApi convertApi = new ConvertApi(configuration); string name = "Sample.docx"; //源文档
string format = "rtf";//转换的目标文档格式
string password = null;//源文档密码
string folder = "input";//源文档的文件夹,如果没有文件夹则为null
string storage = null;//使用冰蓝云配置的2G空间存贮文档,可设置为null
string destFilePath = "output/WordToRTF.rtf";//结果文档路径及名称(结果文档保存在output文件夹下) //调用方法将Word转为RTF
convertApi.ConvertDocument(name, format, password, folder, storage, destFilePath);
}
}
}
5. Docx转Doc
using System;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Api; namespace DocxToDoc
{
class Program
{
static String appId = "App ID";
static String appKey = "APP Key";
static void Main(string[] args)
{
//配置App ID和App Key
Configuration configuration = new Configuration(appId, appKey); //初始化ConvertApi对象
ConvertApi convertApi = new ConvertApi(configuration); string name = "Sample.docx"; //源文档
string format = "doc";//转换的目标文档格式
string password = null;//源文档密码
string folder = "input";//源文档的文件夹,如果没有文件夹则为null
string storage = null;//使用冰蓝云配置的2G空间存贮文档,可设置为null
string destFilePath = "output/DocxToDoc.doc";//结果文档路径及名称(结果文档保存在output文件夹下) //调用方法将Docx转为Doc
convertApi.ConvertDocument(name, format, password, folder, storage, destFilePath);
}
}
}
(本文完)
C# 将Word转为PDF、XPS、Epub、RTF(基于Spire.Cloud.Word.SDK)的更多相关文章
- C# 添加、删除、读取Word形状(基于Spire.Cloud.Word.SDK)
本文介绍调用Spire.Cloud.Word.SDK提供的接口shapesApi来操作Word形状,包括添加形状AddShape(),添加形状时,可设置形状类型.颜色.大小.位置.倾斜.轮廓.文本环绕 ...
- C# 设置、删除、读取Word文档背景——基于Spire.Cloud.Word
Spire.Cloud.Word.Sdk提供了接口SetBackgroudColor().SetBackgroudImage().DeleteBackground().GetBackgroudColo ...
- Java 添加、下载、读取PDF附件信息(基于Spire.Cloud.SDK for Java)
Spire.Cloud.SDK for Java提供了PdfAttachmentsApi接口添加附件addAttachment().下载附件downloadAttachment().获取附件信息get ...
- C# 添加文本、图片到PDF文档(基于Spire.Cloud.PDF.SDK)
Spire.Cloud.PDF.SDK提供了接口PdfTextApi及PdfImagesApi用于添加文本和图片到PDF文档,添加文本时,可格式化文本样式,包括文本字体类型.字号.字体样式.文本颜色. ...
- C# 加密、解密PDF文档(基于Spire.Cloud.SDK for .NET)
Spire.Cloud.SDK for .NET提供了接口PdfSecurityApi可用于加密.解密PDF文档.本文将通过C#代码演示具体加密及解密方法. 使用工具: Spire.Cloud.SDK ...
- Java 将Word转为PDF、PNG、SVG、RTF、XPS、TXT、XML
同一文档在不同的编译或阅读环境中,需要使用特定的文档格式来打开,通常需要通过转换文档格式的方式来实现.下面将介绍在Java程序中如何来转换Word文档为其他几种常见文档格式,如PDF.图片png.sv ...
- C# 将PDF转为Word、Html、XPS、SVG、PCL、PS——基于Spire.Cloud.PDF
Spire.Cloud.PDF提供了接口PdfConvertApi可用于将PDF文档转换为其他格式文档,如Word(docx/doc).Html.XPS.SVG.PCL.PS.Png以及XPS转成PD ...
- ASP.NET Word转为PDF
1.首先安装 Microsoft Office 2007加载项:Microsoft Save as PDF-简体中文版:下载地址: http://download.microsoft.com/down ...
- Java 基于Spire.Cloud.Excel 将Excel转为PDF
Spire.Cloud.Excel Sdk 提供GeneralApi接口和WorkbookApi接口,支持将本地Excel和云端Excel文档转换为ODS, PDF, XPS, PCL, PS等格式. ...
随机推荐
- Activity学习(一):生命周期
一. 认识Activity Activity是Android的四大组件之一,那么它是什么呢?如果简单的理解,可以把它当成应用的一个显示的屏幕. Activity类处于android.app包中,继承体 ...
- Python--day29--configparser模块(配置)(不熟,以后要找时间重学)
- zoj 3652 Maze
Maze Time Limit: 2 Seconds Memory Limit: 65536 KB Celica is a brave person and believer of a Go ...
- [C++] 烦人的error LNK2019和error LNK2001
常见原因: 没有正确的设置引用的lib,新手常犯这个错误,这是最容易解决的问题. extern "C"的问题.如果C++写的dll要给C程序用,那么就要注意extern " ...
- thinkcmf,thinksns,thinkphp,onethink三者是什么关系?
thinksns 是基于tp的老版本二开的 thinkcmf 是网友基于tp开发的cmf thinkphp 是顶想的框架 onethink 是顶想基于tp开发的cmf 官方目前只有ThinkPHP和O ...
- CentOS yum有时出现“Could not retrieve mirrorlist ”的解决办法——resolv.conf的配置
国内服务器在运行命令yum -y install wget的时候,出现: Could not retrieve mirrorlist http://mirrorlist.centos.org/?rel ...
- P3810 陌上花开 CDQ分治
陌上花开 CDQ分治 传送门:https://www.luogu.org/problemnew/show/P3810 题意: \[ 有n 个元素,第 i 个元素有 a_i. b_i. c_i 三个属性 ...
- docker 命令汇总1
命令汇总 docker history fa5fa5为镜像id或者镜像名 docker export 30b >h.tar30b为容器id或者容器名# docker export angry_b ...
- Java 学习笔记(9)——java常用类
之前将Java的大部分语法都回顾完了,后面添加一些常见的操作,基础语法就结束了.至于在这里再次提到常用类是由于有一部分体现在使用它的继承类或者接口之类的.这些需要有面向对象编程的基础 Object类 ...
- 第三阶段:3.Web端产品设计:4.产品设计-交互设计
交互设计主要做框架层以及结构层.包括交互关系,信息结构,界面布局,导航设计,信息内容. 导航关系非常重要. 这是框架层. 这是结构层. 要素就是信息内容.