C# 实现Word 转成图片 利用 Aspose.Words.dll

Word转成图片,办法有很多。今天给大家介绍一下,使用Aspose.Words.dll实现

首先在项目中添加对Aspose.Words.dll的引用。代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Aspose.Words;
using Aspose.Words.Saving;
using System.IO;

namespace NewConvertBook
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //读取doc文档
            Document doc = new Document(@"C:\Users\Administrator\Desktop\temp测试 .doc");

            //保存为PDF文件,此处的SaveFormat支持很多种格式,如图片,epub,rtf 等等
            ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.Png);
            imageOptions.PrettyFormat = true;
            imageOptions.Resolution = 150;//设置图片质量(越大越清晰)

            for (int i = 0; i < doc.PageCount; i++) 
            {
                imageOptions.PageIndex = i;
                doc.Save("temp" + i.ToString() + ".png", imageOptions);
            }

        }
    }
}

可以支持jpeg(SaveFormat.Jpeg),png(SaveFormat.Png),bmp(SaveFormat.Bmp) 三种格式的图片。