Automatically generate thumbnails for uploading Office files and upload office files

Source: Internet
Author: User

Automatically generate thumbnails for uploading Office files and upload office files

Not long ago, the product manager raised a demand for "X", saying that the homepage should be automatically uploaded to display the first page thumbnail of the file when the file list is displayed.
There are many implementation methods. Here we will introduce you to a simple and practical solution, which is very convenient to use.

1. The Aspose. Pdf function converts a pdf file to an image. You can use aspose to read the first page and save it as an image.

// Filestream is a PDF file stream

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

// SaveDirectory is the location where the file is saved

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

Resolution resolution = new Resolution (300 );

Specify device resolution device = new resolution device (resolution, 100); // Save the first page as an image

Using device. Process (using document. Pages [1], imageStream );

ImageStream. Close ();

}

1. Aspose. Cells converts an excel image to an image, obtains an excel [Sheet1], reads and saves it as an image through 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. The Aspose. Words function converts word into an image, and obtains the word file stream, which is read and saved as an image through aspose.

Aspose. Words. Document doc = new Aspose. Words. Document (filestream );

Doc. Save (saveDirectory, Aspose. Words. SaveFormat. Jpeg );

Is it very convenient? You only need to obtain the file stream during file upload and save it as an image through Aspose. Of course, Aspose has more powerful functions. Here we just use it to save a thumbnail, it can flexibly convert the corresponding files, but the Aspose dll is a paid cracked version that can only convert three pages of content, but it is enough to create a homepage function to crack the version!

Http://mp.weixin.qq.com/s? _ Biz = MzIzNTE2OTk1MA ==& mid = 402768932 & idx = 1 & sn = 0f091d8a9ebf006f5e5d128304d06e63 # rd
You can scan the QR code to add a CodeL public account and leave a message for related resources or other questions. (Public Account: codelir)

Scan to get more development resources:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.