using System;
using System.Collections.Generic;
using System.Text;
using OMCS.Engine.WhiteBoard;
using ESBasic;
using System.Drawing.Imaging;
using System.IO;
using System.Drawing;
using Schematrix;
namespace OMCS.Demos.WhiteBoardTest
{
/**//*
*
* 将pdf、ppf、word转换给图片的组件有很多,这里仅使用Aspose组件(试用版)作为示例。
*
*
*/
图片转换器工厂 -> 将被注入到OMCS的多媒体管理器IMultimediaManager的ImageConverterFactory属性#region 图片转换器工厂 -> 将被注入到OMCS的多媒体管理器IMultimediaManager的ImageConverterFactory属性
/** <summary>
/// 图片转换器工厂。
/// </summary>
public class ImageConverterFactory : IImageConverterFactory
{
public IImageConverter CreateImageConverter(string extendName)
{
if (extendName == ".doc" || extendName == ".docx")
{
return new Word2ImageConverter();
}
if (extendName == ".pdf")
{
return new Pdf2ImageConverter();
}
if (extendName == ".ppt" || extendName == ".pptx")
{
return new Ppt2ImageConverter();
}
if (extendName == ".rar")
{
return new Rar2ImageConverter();
}
return null;
}
public bool Support(string extendName)
{
return extendName == ".doc" || extendName == ".docx" || extendName == ".pdf" || extendName == ".ppt" || extendName == ".pptx" || extendName == ".rar";
}
}
#endregion
将word文档转换为图片#region 将word文档转换为图片
public class Word2ImageConverter : IImageConverter
{
private bool cancelled = false;
public event CbGeneric<int, int> ProgressChanged;
public event CbGeneric ConvertSucceed;
public event CbGeneric<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);
}
/** <summary>
/// 将Word文档转换为图片的方法
/// </summary>
/// <param name="wordInputPath">Word文件路径</param>
/// <param name="imageOutputDirPath">图片输出路径,如果为空,默认值为Word所在路径</param>
/// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
/// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
/// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
/// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
private void 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)
{
throw new Exception("Word文件无效或者Word文件被加密&#
使用Aspose组件将WORD、PDF、PPT转为图片
最新推荐文章于 2024-07-18 13:38:27 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)