C#实现 word、pdf、ppt 转为图片

: IImageConverter{private bool cancelled = false;<int, int> ProgressChanged;ConvertSucceed;<string> ConvertFailed;public void Cancel(){if (this.cancelled){return;}this.cancelled = true;}public void ConvertToImage(string originFilePath, string imageOutputDirPath){this.cancelled = false;ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, null, 200);} 将Word文档转换为图片ConvertToImage(string wordInputPath, string imageOutputDirPath, int startPageNum, int endPageNum, ImageFormat imageFormat, int resolution){try{Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);if (doc == null){();}if (imageOutputDirPath.Trim().Length == 0){imageOutputDirPath = Path.GetDirectoryName(wordInputPath);}if (!Directory.Exists(imageOutputDirPath)){Directory.CreateDirectory(imageOutputDirPath);}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;}string imageName = Path.GetFileNameWithoutExtension(wordInputPath);ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.Png);imageSaveOptions.Resolution = resolution;for (int i = startPageNum; i <= endPageNum; i++){if (this.cancelled){break;}MemoryStream stream = new MemoryStream();imageSaveOptions.PageIndex = i – 1;+ i.ToString() + + imageFormat.ToString();doc.Save(stream, imageSaveOptions);Image img = Image.FromStream(stream);Bitmap bm = ESBasic.Helpers.ImageHelper.Zoom(img, 0.6f);bm.Save(imgPath, imageFormat);img.Dispose();stream.Dispose();bm.Dispose();System.Threading.Thread.Sleep(200);if (this.ProgressChanged != null){this.ProgressChanged(i – 1, endPageNum);}}if (this.cancelled){return;}if (this.ConvertSucceed != null){this.ConvertSucceed();}}catch (Exception ex){if (this.ConvertFailed != null){this.ConvertFailed(ex.Message);}}}}

版权声明:本文为博主原创文章,未经博主允许不得转载。

上一篇C#实现麦克风采集与播放

顶1踩0

,怠惰是贫穷的制造厂。

C#实现 word、pdf、ppt 转为图片

相关文章:

你感兴趣的文章:

标签云: