原文:html
http://www.knowsky.com/898407.html微信
上传office文件的时候须要将首页自动截图,用于显示文件列表的时候将文件第一页缩略图展现给用户。
实现的方式有多种,这里给你们介绍一个简单实用的方案,用起来很是方便。excel
1.aspose.Pdf实现将pdf转换为图片功能,获取pdf文件流 经过aspose读取第一页保存为图片code
//filestream为pdf文件流orm
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(filestream);htm
//saveDirectory为保存文件的位置图片
using (FileStream imageStream = new FileStream(saveDirectory, FileMode.Create)){资源
Resolution resolution = new Resolution(300);开发
JpegDevice jpegDevice = new JpegDevice(resolution, 100);//将第一页保存为图片get
jpegDevice.PRocess(pdfDocument.Pages[1], imageStream);
imageStream.Close();
}
1.Aspose.Cells实现将Excel转换为图片功能,获取excel[Sheet1] ,经过aspose读取保存为图片
Workbook workbook = new Workbook(filestream);
Worksheet sheet = workbook.Worksheets[0];
sheet.PageSetup.LeftMargin = 0;
sheet.PageSetup.RightMargin = 0;
sheet.PageSetup.BottomMargin = 0;
sheet.PageSetup.TopMargin = 0;
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = ImageFormat.Jpeg;
imgOptions.OnePagePerSheet = true;
imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;
SheetRender sr = new SheetRender(sheet, imgOptions);
sr.ToImage(0,saveDirectory);
3.Aspose.Words实现将word转换为图片功能,获取word文件流 经过aspose读取保存为图片
Aspose.Words.Document doc = new Aspose.Words.Document(filestream);
doc.Save(saveDirectory,Aspose.Words.SaveFormat.Jpeg);
是否是很方便,只要把上传文件时文件流获取而后经过Aspose便可保存为图片,固然Aspose拥有更强大的功能,这里只是用它来保存了一张缩略图,它能够将相应的文件相互灵活的转换,不过Aspose的dll是付费的 破解版只能转换3页内容,不过作个首页截图功能破解版的已经够了!
原文连接:http://mp.weixin.QQ.com/s?__biz=MzIzNTE2OTk1MA==&mid=402768932&idx=1&sn=0f091d8a9ebf006f5e5d128304d06e63#rd
相关资源获取或其余疑问可在扫码添加CodeL公众号留言。(微信公众号: codelir)
微信扫一扫获取更多开发资源: