Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert PDF file to images using C#

Using C#, I need to convert each page of a PDF file into separate images and display the images.

Is it possible to do this without using a 3rd party DLL?

like image 600
As k Avatar asked Aug 16 '10 09:08

As k


People also ask

How do I convert a PDF to a DLL?

To show PDF into DLL, you simply have to add a sample, alter it, if required, and save all modifications. The uploading strategies are vast and contain searching a file from the unit, importing it from your cloud, by way of a secure URL, e-mail request, or obtaining a template in the pdfFiller's kind library.


2 Answers

You can also use a c# code that is easly downloadable from Code Project that use Ghostscript

http://www.codeproject.com/KB/cs/GhostScriptUseWithCSharp.aspx

like image 67
Cold Star Avatar answered Oct 16 '22 22:10

Cold Star


Not a huge job, as it has already been done :)

you'll need ghostscript installed (mainly gsdll32.dll), and the c# wrapper from http://redmanscave.blogspot.com/

It's one .cs file. For some reason you'll have to email him for the file, it is not posted.

To convert you'll just a few lines, for example:

    string cl2 = @"-dSAFER -dNoVerifyXref -dQUIET -dNOPROMPT"
      + " -dBATCH -dNOPAUSE -sDEVICE=jpeg -r72 -dFirstPage=1 "
      +  "-dLastPage=1 -dUseCropBox -sOutputFile=" + SourceFile 
      + " " + TargetFile;

    try
    {
        Made4Print.GhostScript gs = 
            new Made4Print.GhostScript(@"[path-to-gs-installation]");
        gs.CallGSDll(cl2.Split(' '));
    }
    catch
    {
        //exception handler
    }    

this saves 1st page as jpeg @ 72 dpi

like image 31
mosheb Avatar answered Oct 16 '22 21:10

mosheb