一款有着强大的文档转换功能的工具,无论何时何地都会是现代办公环境极为需要的。在本篇文章中,将介绍关于Word文档的转换功能(Word转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的更多相关文章

  1. C# Word转为多种格式文件(Word转XPS/SVG/EMF/EPUB/TIFF)

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

  2. Java 将Word转为PDF、PNG、SVG、RTF、XPS、TXT、XML

    同一文档在不同的编译或阅读环境中,需要使用特定的文档格式来打开,通常需要通过转换文档格式的方式来实现.下面将介绍在Java程序中如何来转换Word文档为其他几种常见文档格式,如PDF.图片png.sv ...

  3. C# 将Word转为PDF、XPS、Epub、RTF(基于Spire.Cloud.Word.SDK)

    本文介绍通过调用Spire.Cloud.Word.SDK提供的ConvertApi接口将Word转换为PDF.XPS.Epub.RTF以及将Docx转为Doc格式等.调用接口方法及步骤参考以下步骤: ...

  4. PCB 批量Word转PDF实现方法

    自上次公司电脑中毒带来的影响,导致系统自动生成的Word档PCB出货报告,通过公司邮件服务器以附件的方式发送给客户后,客户是无法打开或打开缓慢的现象,如果将Word档转为PDF后在客户端是可以正常打开 ...

  5. C#,VB.NET如何将Word转换为PDF和Text

    众所周知,Word是我们日常工作中常用的办公软件之一,有时出于某种需求我们需要将Word文档转换为PDF以及Text.那么如何以C#,VB.NET编程的方式来实现这一功能呢? 下面我将分开介绍如何运用 ...

  6. Jacob工具类使用文件互转服务 word转html html转excel word转pdf excel转pdf ppt转pdf

    前提条件  必须安装MS office 1.jdk使用jdk1.8 2.jacob.dll放在..\jdk1.8\jre\bin目录下 3.eclipse的jre版本要和jdk一致,window-&g ...

  7. 利用aspose-words 实现 java中word转pdf文件

    利用aspose-words  实现 java中word转pdf文件 首先下载aspose-words-15.8.0-jdk16.jar包 引入jar包,编写Java代码 package test; ...

  8. ASP.NET Word转为PDF

    1.首先安装 Microsoft Office 2007加载项:Microsoft Save as PDF-简体中文版:下载地址: http://download.microsoft.com/down ...

  9. Word转pdf,再转图片插入PDF

    WORD转PDF所需jar包: https://yangtaotao.lanzous.com/ice1jlc PDF转图片所需jar包: https://yangtaotao.lanzous.com/ ...

随机推荐

  1. 10.Curator队列

        Curator也提供ZK Recipe的分布式队列实现.利用ZK的 PERSISTENTSEQUENTIAL节点,可以保证放入到队列中的项目是按照顺序排队的.如果单一的消费者从队列中取数据,那 ...

  2. 3.html+.ashx(删除学生信息)

    C03ListStu.ashx 0:false(删除);1:true(正常). (数据库里定义个BOOL型,TRUE表示正常FALSE表示删除) <html> <head> & ...

  3. 6.IIs部署与发布

    A.网站的发布步骤: 1.首先要选择要发布的网站(即项目里的网站)也就是代码. 2.左键选择发布. 3.配置文件:Web.congig. 4.连接:publis method:File System, ...

  4. ajax 实现单选按钮的选中值

    <input type=" checked="checked" /> 男     <input type="/>女 $(".s ...

  5. Android N 通知概览及example

    概述 Android App的通知在维护你的App和用户之间的交互起着举足轻重的作用,为了提供更好的用户体验,Android N上的通知提供了可视化刷新,自定义视图和直接回复等功能.另外还提出了Mes ...

  6. SQL---->mySQl数据库1------表的增删改查

    一.创建表(增) 二.删除表(删) drop table 表名; 三.修改表(改) 3.1修改表——>增加一列 3.2修改表——>修改列的值 3.3修改表——>删除列 3.4修改表— ...

  7. vue - 计算属性、表单输入绑定

    计算属性 computed:{} <!DOCTYPE html> <html> <head> <title></title> </he ...

  8. MySQL插入性能优化(转)

    原文:http://tech.uc.cn/?p=634 对于一些数据量较大的系统,数据库面临的问题除了查询效率低下,还有就是数据入库时间长.特别像报表系统,每天花费在数据导入上的时间可能会长达几个小时 ...

  9. python提取相对路径

    原理: 用绝对路径,截断根目录的路径,就得到了相对路径. 代码 方法1:字符串替换(用字符串函数)推荐 import os print('==========1===========') abspat ...

  10. java-基础-【二】内部类与静态内部类

    一.说明 java允许我们在一个类里面定义静态类.比如内部类(nested class).把nested class封闭起来的类叫外部类.在java中,我们不能用static修饰顶级类(top lev ...