I am using the Microsoft API Code Pack and have a handler using the following code
string filename = "C:\Hello.pdf";
ShellFile shellFile = ShellFile.FromFilePath(filename);
Bitmap bitmap = shellFile.Thumbnail.ExtraLargeBitmap;
context.Response.ContentType = "image/jpeg";
bitmap.Save(context.Response.OutputStream, ImageFormat.Jpeg);
This works fine to produce a “preview” style thumbnail for pdf documents, but when I try it with Word or Excel I get the generic thumbnail for the filetype instead of a mini image of the document (which is what I’m looking for).
Anyone have ideas on this? Can it be done using this API?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
As David said, not all Office documents are saved with a thumbnail. It’s a property on the document itself. In Office 2010 you can see the checkbox on the Save As dialog box. In older versions of Office you can find it in the document properties.
Once the Office document is saved with a thumbnail, the code you have will work.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0