600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > Word控件Spire.Doc 转换教程(十二):如何将 Word 转换为 EPub XPS Emf

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

时间:2023-11-08 12:37:59

相关推荐

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

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

Spire.Doc 最新下载

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

EPub是一种电子书格式,以最合适的阅读方式显示内容。因此,通常将Word文档转换为EPub,以给予读者更精彩的阅读效果。本指南演示了使用Spire.Doc轻松将 C# 和 中的 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:\Work\Documents\Spire.Doc for .NET.docx");//Convert Word to EPubdocument.SaveToFile("ToEpub.epub", FileFormat.EPub);System.Diagnostics.Process.Start("ToEpub.epub");}}}

[]

Imports Spire.DocNamespace WordtoEPUBFriend Class EpubShared Sub Main(ByVal args() As String)'Load DocumentDim document As New Document()document.LoadFromFile("E:\Work\Documents\Spire.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 :将 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 的结果。

(三)在 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();}}}

查看下面的效果截图:

欢迎下载|体验更多E-iceblue产品或加入我们的群(767755948)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。