Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export PDF to JPG(s) in C# [closed]

I need to save a one page pdf document as an image for a thumbnail on a website.

I've been messing around with PDFSharp and have had no luck.

I have tried this: http://www.pdfsharp.net/wiki/ExportImages-sample.ashx?AspxAutoDetectCookieSupport=1 but all it does is extract the embedded images in the PDF file which is not the desired result.

Ideas on how to do this? Anyone know a good library that can handle this?

Edit: Please let me know why this is such a bad question. If anyone has a good solution to this it would be a great resource for many other people. Especially since google searches come up empty.

like image 266
Jason Avatar asked Jan 09 '12 01:01

Jason


3 Answers

Take a look at Ghostscript. You can render PDF to images with it.

http://www.mattephraim.com/blog/2009/01/06/a-simple-c-wrapper-for-ghostscript/

like image 136
Jason Avatar answered Nov 01 '22 04:11

Jason


Ghostscript is currently the de-facto standard for rendering PDFs. It's a bit tricky to wrap, even using GhostScriptSharp.

Jason Morse wrote a great C# wrapper for rendering PDFs as a plugin to the open-source imageresizing.net library.

If it's an asp.net application, the library allows on-the-fly rendering, so you can just add a querystring to get the jpeg/png version:

/pdfs/letter.pdf?format=jpg&page=2

You can also use the managed API instead (in any application type - not asp.net specific)

ImageBuilder.Current.Build("letter.pdf","dest.jpg",new ResizeSettings("format=jpg;page=2"));

The PdfRenderer plugin is GPL licensed, just like Ghostscript.

like image 32
Lilith River Avatar answered Nov 01 '22 04:11

Lilith River


ABCpdf exports PDF documents to JPEG with C#. See: http://www.websupergoo.com/helppdfnet/source/4-examples/19-rendering.htm

like image 2
AffineMesh Avatar answered Nov 01 '22 06:11

AffineMesh