Word将文档转为图片时输出图片和源文档格式不一致

我在使用word转图片的时候,输出图片和文档的不一致,以下是我写的转换图片部分代码:

string FileType = System.IO.Path.GetExtension(DocumentsFileName);

            //初始化一个临时参数,到时候重新初始化
            Aspose.Words.Saving.ImageSaveOptions TempWordImageSaveOption = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg);

            Aspose.Words.Document TempWordDocument = null;
switch (FileType)
            {
                case ".doc":
                    TempWordDocument = new Aspose.Words.Document(DocumentsFileName, TempDocuemntLoadOption);
                    TempWordDocument.WarningCallback = AspCallBack;
                    TempWordDocument.CompatibilityOptions.OptimizeFor(Aspose.Words.Settings.MsWordVersion.Word2010);
                    TempWordDocument.CompatibilityOptions.BalanceSingleByteDoubleByteWidth = true;//区分全角和半角字符
                    break;
                case ".docx":
                    TempWordDocument = new Aspose.Words.Document(DocumentsFileName, TempDocuemntLoadOption);
                    TempWordDocument.WarningCallback = AspCallBack;
                    TempWordDocument.CompatibilityOptions.OptimizeFor(Aspose.Words.Settings.MsWordVersion.Word2010);
                    TempWordDocument.CompatibilityOptions.BalanceSingleByteDoubleByteWidth = true;//区分全角和半角字符
                    break;


//根据不同导出类型进行预初始化处理
            switch (ConvertImageType)
            {
                case ".jpg":
                    TempWordImageSaveOption = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg)
                    {
                        JpegQuality = 100,
                        PrettyFormat = true,
                    };
                    TempPdfImageDevice = new Aspose.Pdf.Devices.JpegDevice(TempPdfImageResolution, 100);
                    TempExcelImageOPtion.ImageType = Aspose.Cells.Drawing.ImageType.Jpeg;
                    TempExcelImageOPtion.Quality = 100;
                    break;



//word转图片的设置
            TempWordImageSaveOption.UseHighQualityRendering = true;
            TempWordImageSaveOption.Resolution = DpiValue;
            TempWordImageSaveOption.ColorMode = Aspose.Words.Saving.ColorMode.Normal;
            TempWordImageSaveOption.UseAntiAliasing = true;
            TempWordImageSaveOption.AllowEmbeddingPostScriptFonts = true;


if (PageExport)
            {
                if (FileType == ".doc" || FileType == ".docx")
                {
                    //逐页导出WORD图片
                    for (int pageIndex = 0; pageIndex < TempWordDocument.PageCount; pageIndex++)
                    {
                        string MutilPageFileName = SavedImageFileName.Replace(ConvertImageType, $"_第{pageIndex + 1}页{ConvertImageType}");
                        TempWordImageSaveOption.PageSet = new Aspose.Words.Saving.PageSet(pageIndex);
                        TempWordDocument.Save(MutilPageFileName, TempWordImageSaveOption);
                        if (SetGrayMode)
                        {
                            string SavedPath = Path.GetDirectoryName(SavedImageFileName);
                            string BMP_8BitPath = Path.Combine(SavedPath, "8_bmp_image");
                            Directory.CreateDirectory(BMP_8BitPath);
                            string ConvertedBmpFileName = BMP_8BitPath + "\\" + Path.GetFileName(MutilPageFileName).Replace(ConvertImageType, ".bmp");
                            using Bitmap TempBitMap = new Bitmap(MutilPageFileName);
                            using Bitmap ConvertedBitMap = ConvertTo256Color(TempBitMap);
                            ConvertedBitMap.Save(ConvertedBmpFileName, ImageFormat.Bmp);
                        }
                    }

上述代码只是word转为图片的代码,所以有些是不完整的,大概看下就可以了,是不是我哪里缺参数了还是什么。

然后这是我使用的文档和最终转换结果的附件压缩包,可以打开查看下,我的电脑区域为中国,语言也为中文。

files.zip (270.5 KB)

@jidesheng, 感谢您报告此问题。 我们已经在我们的内部问题跟踪系统中打开了以下新工单,并将根据 免费支持政策 中提到的条款提供它们的修复:

Issue ID(s): WORDSNET-26308

如果您需要优先支持以及直接联系我们的付费支持管理团队,您可以获得 付费支持服务