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?

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

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

Method 2

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

Method 3

I used PDF4NET from O2 a few times in the past and was pretty satisfied
http://www.o2sol.com/pdf4net/overview.htm

Method 4

I have done with this ghost script to convert PDF to Image.hope this one is helpful

“-dNOPAUSE -dBATCH -dSAFER -sDEVICE=tifflzw -dTextAlphaBits=1 -dPDFFitPage -sOutputFile=”C:UserscisDesktopasp634667352520620000.tif” “C:UserscisDesktopasp.pdf””


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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x