
利用Aspose组件将文档转换为图片
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
本文章介绍如何使用Aspose组件高效地将各种文档格式(如.docx、.pdf)转换成高质量的图像文件(如.jpg或.png),适用于需要预览功能的应用场景。
使用Aspose组件将文档转换为图片的代码如下:
```csharp
Console.WriteLine(========文件转图片开始========);
try {
ArrayList fileList = new ArrayList();
fileList.Add(temp_pdf.pdf);
fileList.Add(temp_ppt.ppt);
fileList.Add(temp_pptx.pptx);
fileList.Add(temp_doc.doc);
fileList.Add(temp_docx.docx);
fileList.Add(temp_xls.xls);
fileList.Add(temp_xlsx.xlsx);
for (int i = 0; i < fileList.Count; i++) {
try {
string filePath = fileList[i].ToString();
FileInfo fileInfo = new FileInfo(filePath);
Console.WriteLine(正在转换 + filePath + 文件...);
// 调用AsposeFileToImg类中的方法将文档转为图片
AsposeFileToImg.FileToImg(fileInfo.FullName);
} catch (Exception) {
continue;
}
}
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
Console.WriteLine(========文件转图片结束========);
// 等待用户输入后关闭程序
Console.Read();
```
这段代码首先定义了一个包含需要转换的文档路径列表,然后遍历该列表中的每个文件并调用`AsposeFileToImg.FileToImg()`方法将这些文档转换为图片。如果在处理过程中遇到异常,则会捕获它但不会终止整个程序运行。最后打印出一个消息表示所有文件都已经完成转换,并等待用户输入后结束程序执行。
全部评论 (0)


