资源简介

该项目中包含Aspose.words破解版DLL,以及微软官方的office的插件,测试项目代码。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Imaging;
using Aspose.Words;
using System.IO;
using Aspose.Words.Saving;

namespace Aspose.Word2Image
{
    class Program
    {
        /// 
        /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法:
        /// ConvertPDF2Image(“F:\\PdfFile.doc“ “F:\\“ “ImageFile“ 1 20 ImageFormat.Png 256);
        /// 

        /// Word文件路径
        /// 图片输出路径,如果为空,默认值为Word所在路径
        /// 图片的名字,不需要带扩展名,如果为空,默认值为Word的名称
        /// 从PDF文档的第几页开始转换,如果为0,默认值为1
        /// 从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数
        /// 设置所需图片格式,如果为null,默认格式为PNG
        /// 设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024
        public static void ConvertWordToImage(string wordInputPath string imageOutputPath
            string imageName int startPageNum int endPageNum ImageFormat imageFormat float resolution)
        {
            try
            {
                // open word file
                Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);

                // validate parameter
                if (doc == null) { throw new Exception(“Word文件无效或者Word文件被加密!“); }
                if (imageOutputPath.Trim().Length == 0) { imageOutputPath = Path.GetDirectoryName(wordInputPath); }
                if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
                if (imageName.Trim().Length == 0) { imageName = Path.GetFileNameWithoutExtension(wordInputPath); }
                if (startPageNum <= 0) { startPageNum = 1; }
                if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
                if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
                if (imageFormat == null) { imageFormat = ImageFormat.Png; }
                if (resolution <= 0) { resolution = 128; }

                ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat));
                imageSaveOptions.Resolution = resolution;

                // start to convert each page
                for (int i = startPageNum; i <= endPageNum; i++)
                {
                    imageSaveOptions.PageIndex = i - 1;
                    doc.Save(Path.Combine(imageOutputPath imageName) + “_“ + i.ToString() + “.“ + imageFormat.ToString() imageSaveOptions);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
        {
            SaveFormat sf = SaveFormat.

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-02-22 19:07  WORD2IMAGE\
     目录           0  2012-02-22 19:06  WORD2IMAGE\Aspose.word2image\
     文件        2856  2012-02-22 19:03  WORD2IMAGE\Aspose.word2image\Aspose.word2image.csproj
     文件        4021  2012-02-22 19:05  WORD2IMAGE\Aspose.word2image\Program.cs
     目录           0  2012-02-22 11:28  WORD2IMAGE\Aspose.word2image\Properties\
     文件        1378  2012-02-22 11:28  WORD2IMAGE\Aspose.word2image\Properties\AssemblyInfo.cs
     目录           0  2012-02-22 19:11  WORD2IMAGE\Microsoft.word2pdf\
     文件        2636  2012-02-22 19:09  WORD2IMAGE\Microsoft.word2pdf\Microsoft.word2pdf.csproj
     文件        4826  2012-02-22 19:09  WORD2IMAGE\Microsoft.word2pdf\Program.cs
     目录           0  2012-02-22 19:07  WORD2IMAGE\Microsoft.word2pdf\Properties\
     文件        1380  2012-02-22 19:07  WORD2IMAGE\Microsoft.word2pdf\Properties\AssemblyInfo.cs
     文件        1449  2012-02-22 19:08  WORD2IMAGE\WORD2IMAGE.sln
     文件       13312  2012-02-22 19:10  WORD2IMAGE\WORD2IMAGE.suo
     目录           0  2012-02-22 19:11  WORD2IMAGE\_dll\
     文件     6597120  2011-10-12 12:49  WORD2IMAGE\_dll\Aspose.Words.dll
     文件      781104  2007-10-10 09:49  WORD2IMAGE\_dll\Microsoft.Office.Interop.Word.dll
     目录           0  2012-02-22 19:11  WORD2IMAGE\_reference\
     文件      955112  2012-02-19 20:01  WORD2IMAGE\_reference\SaveAsPDFandXPS.exe

评论

共有 条评论