Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#/ASP.NET - Get thumbnail from PDF/DOC files

Tags:

c#

asp.net

pdf

doc

I have an ASP.NET WebForms application (written in C#) that allows users to upload files using the FileUpload control.

What'd be great is if I could automatically generate thumbnails from files. Images such as JPG/PNG are trivial of course, but users will often upload .DOC and .PDF files - is there a way I can essentially convert .DOC and .PDF files to images so I can get a thumbnail?

Thanks!

like image 538
Chris Avatar asked Oct 04 '22 14:10

Chris


2 Answers

You can use GhostScriptWrapper for generating image thumbnails directly from pdf.You can get ghostScriptWrapper from GitHub or you can include ghostscript.dll from nuget package manager solution.

like image 120
Shahriar Morshed Avatar answered Oct 06 '22 03:10

Shahriar Morshed


On paper the most hopeful approach would be to do so server side. So, if the file were uploaded, the server could generate a preview image.

On Windows, there would be a few options.

a) Windows Shell has a way to do it. The path is dangerous though. b) https://filepreviews.io/ Is a service that does it, but they charge. c) box is another service that does it.

Now on Linux, or even, perhaps, a Linux in a Windows subsystem, could do it with some command line utilities.

a) Convert the doc to pdf:

Convert DOC to PDF

b) Then, get a bitmap of the first page of the pdf, use ghostscript. ghostscript also exists for .NET and Windows.

Bitmap of PDF First Page

like image 44
TJ Bandrowsky Avatar answered Oct 06 '22 03:10

TJ Bandrowsky