zoukankan      html  css  js  c++  java
  • Office文件上传自动生成缩略图-C#开发

    原文:

    http://www.knowsky.com/898407.html

    上传office文件的时候需要将首页自动截图,用于显示文件列表的时候将文件第一页缩略图展示给用户。
    实现的方式有多种,这里给大家介绍一个简单实用的方案,用起来非常方便。

    1.aspose.Pdf实现将pdf转换为图片功能,获取pdf文件流 通过aspose读取第一页保存为图片

      //filestream为pdf文件流

    Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(filestream);

    //saveDirectory为保存文件的位置

    using (FileStream imageStream = new FileStream(saveDirectory, FileMode.Create)){

    Resolution resolution = new Resolution(300);

    JpegDevice jpegDevice = new JpegDevice(resolution, 100);//将第一页保存为图片

    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)

    微信扫一扫获取更多开发资源:

  • 相关阅读:
    哈希表(开放定址法处理冲突)(1013)
    哈希表(链地址法处理冲突)(1012)
    求最小生成树(Prim算法)(1075)
    POJ 1061 青蛙的约会(扩展欧几里得)
    小偷的背包(0963)
    20169208 2016-2017-2《网络攻防实践》课程总结
    20169208 2016-2017-2 《网络攻防实践》第十四周学习总结
    20169208 2016-2017-2 《网络攻防实践》第十一周学习总结
    20169208 2016-2017-2 《网络攻防实践》第10周学习总结
    20169208 2016-2017-2 《网络攻防实践》nmap扫描实践
  • 原文地址:https://www.cnblogs.com/guo2001china/p/5217736.html
Copyright © 2011-2022 走看看