C#中Word如何转PDF/HTML/XML/XPS/SVG/EMF/EPUB/TIFF格式
发表于:2025-11-10 作者:千家信息网编辑
千家信息网最后更新 2025年11月10日,这篇文章主要介绍了C#中Word如何转PDF/HTML/XML/XPS/SVG/EMF/EPUB/TIFF格式,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编
千家信息网最后更新 2025年11月10日C#中Word如何转PDF/HTML/XML/XPS/SVG/EMF/EPUB/TIFF格式
这篇文章主要介绍了C#中Word如何转PDF/HTML/XML/XPS/SVG/EMF/EPUB/TIFF格式,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
使用工具:Free Spire.Doc for .NET(社区版)
使用方法:下载安装该控件后,在VS控制台应用程序中添加引用Spire.Doc.dll文件(dll文件可在该安装文件夹下Bin中获取)
1.Word转PDF/HTML/XML
using Spire.Doc;namespace Doc2PDF{ class Program { static void Main(string[] args) { //创建一个Document类对象,并加载Word文档 Document document = new Document(); document.LoadFromFile(@"C:\Users\Administrator\Desktop\Test.docx"); //调用方法SaveToFile()将Word转为PDF、HTML和XML document.SaveToFile("Test.PDF", FileFormat.PDF); document.SaveToFile("Test.html", FileFormat.Html); document.SaveToFile("Test.xml", FileFormat.Xml); //运行生成的文档 System.Diagnostics.Process.Start("Test.PDF"); System.Diagnostics.Process.Start("Test.html"); System.Diagnostics.Process.Start("Test.xml"); } }}
2.Word转XPS
using Spire.Doc;using System;namespace WordtoXPS_Doc{ class Program { static void Main(string[] args) { //初始化String类,元素为需要转换的Word文档 String file = "sample.docx"; //创建一个Document类对象,加载sample文件 Document doc = new Document(file); //将Word文件保存为XPS,并运行生成的文档 doc.SaveToFile("Word2XPS.xps", FileFormat.XPS); System.Diagnostics.Process.Start("Word2XPS.xps"); } }}调试运行该项目生成文档,如下图:
3.Word转SVG
using Spire.Doc;namespace WordtoSVG_Doc{ class Program { static void Main(string[] args) { //实例化Document类,并加载Word sample Document doc = new Document(); doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.docx"); //保存为svg格式 doc.SaveToFile("result.svg", FileFormat.SVG); } }}4. Word转Emf
using Spire.Doc;using System.Drawing;using System.Drawing.Imaging;namespace WordtoEmf_Doc{ class Program { static void Main(string[] args) { //实例化一个Document类,并加载Word sample Document doc = new Document(); doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.docx", FileFormat.Docx); //调用方法 SaveToImages()将Word第一页转为image并保存为Emf格式 System.Drawing.Image image = doc.SaveToImages(0, Spire.Doc.Documents.ImageType.Metafile); image.Save("WordtoEmf.emf", ImageFormat.Emf); } }}5. Word转Epub
using Spire.Doc;namespace WordtoEPUB{ class Epub { static void Main(string[] args) { //实例化Document类,并加载Word sample Document document = new Document(); document.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.docx"); //保存为Epub格式,并运行生成的文档 document.SaveToFile("ToEpub.epub", FileFormat.EPub); System.Diagnostics.Process.Start("ToEpub.epub"); } }}6. Word转Word XML
using Spire.Doc;namespace WordtoWordXML_Doc{ class Program { static void Main(string[] args) { //创建一个Document类对象并加载Word sample Document doc = new Document(); doc.LoadFromFile("sample.docx"); //调用方法SaveToFile()保存Word为Word Xml doc.SaveToFile("WordToWordXML.xml", FileFormat.WordXml); } }}7. Word转Tiff
using Spire.Doc;using Spire.Doc.Documents;using System;using System.Drawing;using System.Drawing.Imaging;namespace convert_word_to_tiff{ class Program { static void Main(string[] args) { //实例化一个Document类,加载Word sample Document document = new Document(@"C:\Users\Administrator\Desktop\sample.docx"); //调用方法JoinTiffImages()将Word保存为tiff格式,并运行生成的文档 JoinTiffImages(SaveAsImage(document), "result.tiff", EncoderValue.CompressionLZW); System.Diagnostics.Process.Start("result.tiff"); } //自定义方法SaveAsImage()将Word文档保存为图像 private static Image[] SaveAsImage(Document document) { Image[] images = document.SaveToImages(ImageType.Bitmap); return images; } private static ImageCodecInfo GetEncoderInfo(string mimeType) { ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders(); for (int j = 0; j < encoders.Length; j++) { if (encoders[j].MimeType == mimeType) return encoders[j]; } throw new Exception(mimeType + " mime type not found in ImageCodecInfo"); } //自定义方法JoinTiffImages()将Word保存为TIFF图片格式(使用指定编码器和图像编码参数) public static void JoinTiffImages(Image[] images, string outFile, EncoderValue compressEncoder) { System.Drawing.Imaging.Encoder enc = System.Drawing.Imaging.Encoder.SaveFlag; EncoderParameters ep = new EncoderParameters(2); ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame); ep.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)compressEncoder); Image pages = images[0]; int frame = 0; ImageCodecInfo info = GetEncoderInfo("image/tiff"); foreach (Image img in images) { if (frame == 0) { pages = img; pages.Save(outFile, info, ep); } else { ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage); pages.SaveAdd(img, ep); } if (frame == images.Length - 1) { ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush); pages.SaveAdd(ep); } frame++; } } }}感谢你能够认真阅读完这篇文章,希望小编分享的"C#中Word如何转PDF/HTML/XML/XPS/SVG/EMF/EPUB/TIFF格式"这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!
文档
格式
方法
文件
生成
运行
实例
篇文章
对象
C#
图像
编码
价值
使用方法
元素
兴趣
参数
可在
同时
图片
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
微信小程序数据库随机数据
苏州安卓软件开发教程
广东戴尔服务器维修价格
彩票软件开发目的
服务器端口的企业管理器在哪
云服务器上运行ipfs
抗疫在家网络安全在心中手抄报
qq安全连接到服务器
云南销售软件开发商
成立网络安全 小组
网络安全警务室授牌仪式致辞
网络安全宣传搞笑片
www服务器的任务
个人服务器需要的配置
连云港市网络安全领导小组
数据库支持包含
网络安全手术
焰火移动互联网科技有限公司
赴日软件开发一个月存多少钱
供热软件开发公司电话
软件开发算法基础
崇明区通用软件开发产品介绍
电脑时间与网络同步的服务器
派出所检查督导厂矿网络安全
网络安全手抄报的字清晰
青海省网络安全监管中心表格
学习app软件开发多长时间
win7对应的服务器版本是什么
市委网信办开展网络安全专项检查
数据库文档两种类型是