C#Word转为多种格式文件(Word转XPSSVGEMFEPUBTIFF)

C#Word转为多种格式文件(Word转XPSSVGEMFEPUBTIFF),第1张

概述一款有着强大的文档转换功能的工具,无论何时何地都会是现代办公环境极为需要的。在本篇文章中,将继续介绍关于Word文档的转换功能(Word转XPS/SVG/EMF/EPUB/TIFF)希望方法中的代码能

一款有着强大的文档转换功能的工具,无论何时何地都会是现代办公环境极为需要的。在本篇文章中,将继续介绍关于Word文档的转换功能(Word转XPS/SVG/EMF/EPUB/TIFF)希望方法中的代码能为各位开发者们提供一定的参考价值。

PS:更多Word转换功能可以参阅这两篇文章

Word转HTML/XML/PDF/IMAGEWord转TXT

使用工具:Free Spire.Doc for .NET

使用方法:下载安装该控件后,在VS控制台应用程序中添加引用Spire.Doc.dll文件(dll文件可在该安装文件夹下Bin中获取)

1. Word转XPS
using Spire.Doc; 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();        }    }}

调试运行该项目生成文档,如下图:

2.  Word转SVG
 Spire.Doc; WordtoSVG_Doc{    实例化document类,并加载Word sample            document doc =  document();            doc.LoadFromfile(@"C:\Users\administrator\Desktop\sample.docx);            保存为svg格式            doc.Savetofile(result.svg

3. Word转Emf
 System.Drawing; System.Drawing.Imaging; WordtoEmf_Doc{    实例化一个document类,并加载Word sample            document doc = 调用方法 SavetoImages()将Word第一页转为image并保存为Emf格式            System.Drawing.Image image = doc.SavetoImages(0WordtoEmf.emf

4.  Word转Epub
 WordtoEPUB{     Epub    {        实例化document类,并加载Word sample            document document =  document();            document.LoadFromfile();            保存为Epub格式,并运行生成的文档            document.Savetofile(ToEpub.epub);        }    }}

5. Word转Word XML
 WordtoWordXML_Doc{    创建一个document类对象并加载Word sample            document doc = 调用方法Savetofile()保存Word为Word Xml            doc.Savetofile(WordToWordXML.xml

6.   Word转Tiff
 Spire.Doc.documents; System; convert_word_to_tiff{    实例化一个document类,加载Word sample            document document = new document(调用方法JoinTiffImages()将Word保存为tiff格式,并运行生成的文档            JoinTiffImages(SaveAsImage(document),result.tiff);        }        自定义方法SaveAsImage()将Word文档保存为图像        private static Image[] SaveAsImage(document document)        {            Image[] images = document.SavetoImages(ImageType.Bitmap);            return images;        }        static ImageCodecInfo GetEncoderInfo( mimeType)        {            ImageCodecInfo[] encoders = ImageCodecInfo.GetimageEncoders();            for (int j = 0; j < encoders.Length; j++)            {                if (encoders[j].MimeType == mimeType)                     encoders[j];            }            throw new Exception(mimeType +  mime type not found in ImageCodecInfo自定义方法JoinTiffImages()将Word保存为TIFF图片格式(使用指定编码器和图像编码参数)        public voID JoinTiffImages(Image[] images, 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,1)">)compressEncoder);            Image pages = images[];            int frame = ;            ImageCodecInfo info = GetEncoderInfo(image/tiffforeach (Image img in images)            {                if (frame == )                {                    pages = img;                                       pages.Save(outfile,info,ep);                }                else                {                    ep.Param[)EncoderValue.FrameDimensionPage);                    pages.SaveAdd(img,ep);                }                if (frame == images.Length - 1)                {                                        ep.Param[)EncoderValue.Flush);                    pages.SaveAdd(ep);                }                frame++;            }        }    }}

以上是本次关于Word转成其他格式文件的具体描述,方法中的代码供参考。欢迎转载(转载请注明出处)

 

总结

以上是内存溢出为你收集整理的C# Word转为多种格式文件(Word转XPS/SVG/EMF/EPUB/TIFF)全部内容,希望文章能够帮你解决C# Word转为多种格式文件(Word转XPS/SVG/EMF/EPUB/TIFF)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1213403.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-04
下一篇2022-06-04

发表评论

登录后才能评论

评论列表(0条)

    保存