Word控件Spire.Doc 转换教程(十二):如何将 Word 转换为 EPub、XPS、Emf

本文将介绍一种通过名为 Spire.Doc 的强大且独立的Word .NET 组件将 Word 转换为 EPub、XPS、Emf的简单方法!

本文将介绍一种通过名为 Spire.Doc 的强大且独立的Word .NET 组件将 Word 转换为 EPub、XPS、Emf的简单方法,无需在机器上安装 Microsoft Word。它还支持将 Word 和HTML转换为常用的图像格式,如 Jpeg、Png、Gif、Bmp 和Tiff等。

(一)在 C#、VB.NET 中将 Word 转换为 EPub

EPub是一种电子书格式,以最合适的阅读方式显示内容。因此,通常将Word文档转换为EPub,以给予读者更精彩的阅读效果。本指南演示了使用Spire.Doc轻松将 C# 和 VB.NET 中的 Word 转换为 EPub 的解决方案。以下屏幕截图显示了从 Word 转换后的 EPub 文件。

word转Epub

Spire.Doc for .NET 提供了Document类的SaveToFile(String fileName, FileFormat fileFormat)方法,用于将 Word 转换为 EPub 或其他文档格式。调用此方法将 Word 转换为 EPub 时,参数 String fileName 的扩展名应为 .epub,并且在选项中应选择 enum FileFormat 作为 EPub。下载并安装 Spire.Doc for .NET并遵循以下代码:

[C#]

using Spire.Doc;namespace WordtoEPUB{class Epub{static void Main(string[] args){//Load DocumentDocument document = new Document();document.LoadFromFile(@"E:WorkDocumentsSpire.Doc for .NET.docx");//Convert Word to EPubdocument.SaveToFile("ToEpub.epub", FileFormat.EPub);System.Diagnostics.Process.Start("ToEpub.epub");}}}

[VB.NET]

Imports Spire.DocNamespace WordtoEPUBFriend Class EpubShared Sub Main(ByVal args() As String)'Load DocumentDim document As New Document()document.LoadFromFile("E:WorkDocumentsSpire.Doc for .NET.docx")'Convert Word to EPubdocument.SaveToFile("ToEpub.epub", FileFormat.EPub)System.Diagnostics.Process.Start("ToEpub.epub")End SubEnd ClassEnd Namespace

Spire.Doc 是无需自动化即可操作 MS Word 文档的专业独立组件,使开发人员能够在其 .NET、WPF 和 Silverlight 应用程序上生成、读取、写入、修改 Word 文档。


(二)在 C# 中将 Word 转换为 XPS

XML 纸张规范 (XPS) 为分页的可打印文档指定了一组文档布局功能。与 Adobe System 的 PDF 格式一样,XPS 是一种固定布局的文档,旨在保持文档保真度,提供与设备无关的文档外观。

我们的许多客户要求的转换是 DOC/DOCX 到 XPS in.NET:将 Word 文档转换为 XPS 文件。Spire.Doc for .NET 允许您将 Word(Doc/Docx) 转换为 XPS。您可以使用 spire.doc 汇编的方法转换 word 文档。

[C#]

using System;using System.Collections.Generic;using System.Text;using Spire.Doc;namespace Doc_to_xps{class Program{static void Main(string[] args){//doc fileString file = "doc to xpsdoc.docx";//open doc documentDocument doc = new Document(file);//convert to xps file.doc.SaveToFile("doc to xpsSample.xps", FileFormat.XPS);System.Diagnostics.Process.Start("doc to xpsSample.xps");}}}

查看以下C#代码,首先实例化一个document对象,调用Load File方法加载一个doc文档。然后将此文档数据保存为 XPS 格式。

[C#]

//doc fileString file = "doc to xpsdoc.docx";//open doc documentDocument doc = new Document(file);//convert to xps file.doc.SaveToFile("doc to xpsSample.xps", FileFormat.XPS);System.Diagnostics.Process.Start("doc to xpsSample.xps");

以下屏幕截图显示了将 Word 转换为 XPS 的结果。

Word 转换为 XPS
(三)在 C# 中将 Word 转换为 Emf

Emf 是增强型 MetaFile 的文件扩展名,用作 Windows 操作系统的打印机驱动程序的图形语言。1993 年,带有附加命令的更新版本 32 位版本的 Win32/GDI 引入了增强元文件 (Emf)。Microsoft 还建议使用增强格式 (Emf) 函数,而不是很少使用的 Windows 格式 (WMF) 函数。

Spire.Doc 提供了通过以下 5 行简单代码将 Word 转换为 Emf 的几乎最简单的解决方案。

[C#]

using Spire.Doc;using System.Drawing.Imaging;namespace DOCEMF{class Program{static void Main(string[] args){// create an instance of Spire.Doc.DocumentDocument doc = new Document();// load the file base on a specified file namedoc.LoadFromFile(@"../../Original Word.docx", FileFormat.Docx);//convert the first page of document to imageSystem.Drawing.Image image = doc.SaveToImages(0, Spire.Doc.Documents.ImageType.Metafile);// save the document object to Emf fileimage.Save(@"../../Convert Word to Image.emf", ImageFormat.Emf);//close the documentdoc.Close();}}}

查看下面的效果截图:

word转 emf c#

 


欢迎下载|体验更多E-iceblue产品 
如需获取相关产品信息,请您咨询在线客服

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年1月6日
下一篇 2022年1月6日

相关推荐

发表回复

登录后才能评论