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

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!

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.

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

For PDf you can try ABCPDF from websupergoo. With that you should be able to generate a thumbnail,
Documentation link for creating a PNG from a PDF. http://www.websupergoo.com/helppdf8net/source/4-examples/19-rendering.htm
also for Doc, it is a little more complex, you are going to have to install the office application on the server that host the apps and from there manipulate the image.
Look at this article. It lets you extract the thumbnail image that Windows Explorer uses for Office documents and regular images.
http://msdn.microsoft.com/en-us/library/aa289172.aspx

Related

Showing a small size sight of documents

I use a file uploader and a user can upload .pdf, .jpg, .doc etc.
I have a grid like below at the web page:
At that grid I show the list of documents. And I want to show them like below:
Any idea? How can I do it? Are there any example?
I want to show a small size sight of documents in order to faciliate understanding at the first look.
If there were only image, I could use thumbnail for it but there are docs and pdf also..
(And the each sights should be an image of each document)
If you are running your server on windows you can use the shell's thumbnails. See this. That way you will get thumbnails for the images and a different icon dependng on the file type. Maybe you can even get it to work with PDF and DOC files, but that's a matter of fidding with the shell. On my machine (64-bit) I don't get thumbnails but there are fixes available.
Update: I followed the instructions at the end of this article and got thumbnails woking on my shell.
In order for this to work you will need to install MS office and adobe reader on the server, or at least create fake file associations.

.NET graphic libraries to display images (pdf, .docx and any other format of image) in the browser

I am developing a ASP .NET MVC application where users are able to upload files to a repository. Those files could be pdf, doc, any type of image and so on.
When the user select a file to be imported I would like to display this file in the browser so they can review its contents before the upload.
I know I could use some sort of IFrame to display pdf but I am looking for some specific class or .net libraries to implement this feature.
I just need a north.
This is an extremely difficult problem. There are some libraries that can help. For instance PDF files might be rendered to images with ghostscript. Word and Excel files might be converted to PDF or image with a number of libraries. None of them, AFAIK, are very good at it so I can not recommend one.
You could automate MSO to perform the conversion to PDF, but that is decidedly not safe for server code. Another possibility is convert source documents to SWF files (like flexpaper) and display in flash. There are some great libraries out there, but it will limit your supported clients. Sharepoint has support for providing some of this capability as well. Others have used OpenOffice to convert MSO documents but also at a loss of quality.
I can't really advise any specific direction as it is highly dependent on what you/your company is willing to spend and the desired results. Good luck.
You could try to rely on Windows and the explorer thumbnails for it, like here, but then you'd have to make sure that:
You can abuse the server in the most elaborate way (install stuff, talk to the shell from ASP.NET)
You have a thumbnail provider installed on the server for every type that you want to preview. I guess from the moment you can see the thumbnail in explorer, you're set. So for pdf, you might need to install PDF Reader from Adobe.
Docx files should be saved with thumbnail checked (see link). There seems to be no other easy, free way to convert a docx to a thumbnail. The "best" solution I came across, was saving it automatically again somehow, and making sure the thumbnail option is checked.
I don't want to say that's impossible, but it can't be done with finite effort.
What you are asking for is a browser-based solution, because you want the user to be able to "review" the document before uploading.
Therefore you cannot use a server side solution, which is essentially what is being asked by referring to a ".Net library".
.Net libraries are dependent on an installed version of .Net, which does not exist in all versions for all operating systems for which graphical browsers exist.
Next, recent changes in browser security do not allow to read the full client-side file name of the selected file in the input field.
You'd have to rely on HTML5 and its FileReader to access the file's byte stream, but even then you can only retrieve image from image files. (see sample)
Excluding browser-based solutions in Flash, ActiveX, Java, due to browser and platform support, this leaves JavaScript as the only "reasonable" solution: you'd need a library for each supported format to either convert a file into an image in an image format supported by browsers, or extract the text(+image) representation of a file.
Great awnsers... Just want to share the result of my research and I found a nice client-based solution supported by Mozilla Labs. This is a framework based on HTML5 and Javascript with no native code needed.
Here the project website:
https://github.com/mozilla/pdf.js
This is what you are capable of:
http://mozilla.github.com/pdf.js/web/viewer.html
And for the last a great video explaning how everthing works
http://www.youtube.com/watch?v=Iv15UY-4Fg8&noredirect=1
Reguarding my question we are going to converter every possible file to PDF on the server and then render this PDF using this framework.

how to upload bmp bitmap image in silverlight?

I am writing a code in silverlight. I want to upload images on my silverlight application. Please help me how do I upload bitmap images and show them on interface. If I am wrong please sort it out.thanks
Silverlight only natively supports .jpg and .png files. You will need a third party library to decode (or convert) bmp files for use by Silverlight.
You could potentially show them in a web browser control within Silverlight, but MS chose PNG and JPG for a reason, so why add complexity.I'd say convert them on the server after upload using one of many third party libraries available.
Can you provide some more detail? Do you want to upload this to a directory on your site, store it within a DB or just retain it for the session and then dispose of the image?
There are a number of examples such as Silverlight File Upload on codeplex. or File Uploader. If you are looking to upload to just a directory on your website you may want to look at this example as well.
Aside from those starting points you need to provide some more detail as where you are having issues.

how do I generate preview image based on first page of a PDF or PPT/PPTX or DOC/DOCX in ASP.NET C#

I have read all references and haven't found a solution on it.
Is there any 3rd-party component in .NET available for doing such a job? such as converting documents (doc, pdf, ppt, xls....) into images?
thank you very much and I'm waiting online...
You may want to take a look at ImageGlue.
As for the MS Office formats, I think the files need to have the thumbnail option enabled for ImageGlue to get the preview image.
My company implements a Digital Asset Management system that uses ImageGlue to generate preview images for a lot of different file formats, so it should definitely do the trick.

Pdf printer driver C#

I am looking for a free open source .Net based (prefer C#) pdf driver. Any idea where I can download one?
Pdf Creator
PDFCreator easily creates PDFs from any Windows program. Use it like a printer in Word, StarCalc or any other Windows application.
If you need to use created PDF file inside of your C# application, then the easiest way is to generate PDF inside this application. Then you don't need to monitor a temp folder for a new file created.
To generate PDF inside of your application you will need a PDF-generating library for C#.
For example, PDFFlow library. You can generate all the elements of PDF document (text element, paragraph, image, inline image, line, table, page number, header/footer, etc...), so you can construct "any kind of document", as you said.
Hope, this idea will help.

Categories