一款有着强大的文档转换功能的工具,无论何时何地都会是现代办公环境极为需要的。在本篇文章中,将介绍关于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. CH1402 后缀数组【Hash】【字符串】【二分】

    1402 后缀数组 0x10「基本数据结构」例题 描述 后缀数组 (SA) 是一种重要的数据结构,通常使用倍增或者DC3算法实现,这超出了我们的讨论范围.在本题中,我们希望使用快排.Hash与二分实现 ...

  2. mybatis-spring-boot-autoconfigure

    mybatis-spring-boot-autoconfigure – MyBatis Sring-BootStarter | Reference Documentation http://www.m ...

  3. CF593C Beautiful Function 构造

    正解:构造 解题报告: 传送门! 我知道我咕了好几篇博客似乎,,,但我不听!我就是要发新博客QAQ!(理不直气也壮 这题,想明白了还是比较简单的QwQ实现起来似乎也没有很复杂QAQ 首先思考一下,显然 ...

  4. 【spring mvc】application context中【bean】的生命周期

    生命周期过程 主要分为四部分: 一.实例化 1. 当调用者通过 getBean( name )向 容器寻找Bean 时,如果容器注册了org.springframework.beans.factory ...

  5. 【开发者笔记】利用shp2pgsql将shape文件导入到postgresql中

    导入shp文件到postgresql中 1.首先,你需要让shp2pgsql命令可用,百度下载,加入环境变量即可. 下载地址:https://download.osgeo.org/postgis/wi ...

  6. Openstack(二)基本环境准备--网络、时间、yum源等

    2.1服务器版本安装 2.1.1服务器使用:centos7.4 + vm12 2.1.2重命名网卡: 传递内核参数 net.ifnames=0 biosdevname=0,以更改网卡名称为eth0,e ...

  7. Spark Streaming里面使用文本分析模型

    功能:接收来自kafka的数据,数据是一篇文章,来判断文章的类型,把判断的结果一并保存到Hbase,并把文章建立索引(没有代码只有一个空壳,可以自己实现,以后有机会了可能会补上) import org ...

  8. PAT 1073 Scientific Notation[字符串处理][科学记数法]

    1073 Scientific Notation(20 分) Scientific notation is the way that scientists easily handle very lar ...

  9. 使用Ajax向服务器端发送请求

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  10. [golang note] 接口使用

    侵入式接口 √ 在其他一些编程语言中,接口主要是作为不同组件之间的契约存在,即规定双方交互的规约. √ 对契约的实现是强制的,即必须确保用户的确实现了该接口,而实现一个接口,需要从该接口继承. √ 如 ...