转Word文档为Tiff格式

 时间:2026-02-14 16:56:09

1、下载并安装Spire.Doc,并将Spire.Doc.dll文件引用到项目中。

2、 将代码放入Visual Studio中:

using Spire.Doc;

using Spire.Doc.Documents;

using System;

using System.Drawing;

using System.Drawing.Imaging;

namespace Word_to_Tiff2

{

    class Program

    {

        static void Main(string[] args)

        {

            Document document = new Document("Sample.docx");

            JoinTiffImages(SaveAsImage(document), "result.tiff", EncoderValue.CompressionLZW);            

        }

        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");

        }

        public static void JoinTiffImages(Image[] images, string outFile, EncoderValue compressEncoder)

        {

            //use the save encoder

            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;

                    //save the first frame

                    pages.Save(outFile, info, ep);

                }

                else

                {

                    //save the intermediate frames

                    ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage);

                    pages.SaveAdd(img, ep);

                }

                if (frame == images.Length - 1)

                {

                    //flush and close.

                    ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush);

                    pages.SaveAdd(ep);

                }

                frame++;

            }

        }

    }

}

3、运行代码后,生成result.tiff文档,在项目Bin文件夹下面手动选择用图片方式打开后,文档如下图所示:

转Word文档为Tiff格式

  • Word使用小技巧:如何设置显示带圈字符
  • 如何根据PPT幻灯片页码自定义导出图片
  • Word2016文档中显示“空格符号”的设置方法
  • 教你word文档中的域怎么用
  • Word中嵌入式的小图片或公式如何与文本对齐?
  • 热门搜索
    防止脱发的最好方法 ip怎么设置 网线怎么拉 鲈鱼的家常做法 面积公式大全 浏览器缓存怎么清理 西安有什么好吃的 我的世界投掷器怎么做 婴儿放屁臭怎么回事 家常红烧豆腐