views:

1407

answers:

3

I would like to convert a PDF file to .GIF using C# and magicknet.dll. I have added the reference to the MagickNet Dll to my project.

MagickNet.Magick.Init();
MagickNet.Image img = new MagickNet.Image("d:/aa.pdf");
img.Write("d:/bb.gif");
MagickNet.Magick.Term();
img.Dispose();
System.Runtime.InteropServices.SEHException was unhandled by user code
  Message="External component has thrown an exception."
  Source="ImageMagickNET"
  ErrorCode=-2147467259
  StackTrace:
       at Magick.Image.{ctor}(Image* , basic_string\,std::allocator >* )
       at ImageMagickNET.Image..ctor(String imageSpec)
       at Test1._Default.Button1_Click(Object sender, EventArgs e) in C:\Users\PANKAJ\Documents\Visual Studio 2008\Projects\Test1\Test1\Default.aspx.cs:line 31
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 
+1  A: 

I think PdfSharp has a way to render PDFs to images. Check their documentation at www.pdfsharp.com.

munissor
+1  A: 

ImageMagick requires GhostScript to Interpret PDF files. If you want you can call the GhostScript dll directly (contact me via my profile, I will send you a c# wrapper)

Alternatively you can use the GhostScript command line or a commercial 3rd party component, eg the PDF libraries from Tall Components.

Mark Redman
hii Mark..thanks you ... actually i have ghostscript dll... but when i add this dll in my program then an error arise ... dat make sure that this dll is accessible and it is a valid com component..
ankush
The GhostScript dll is not a COM component and is an unmanaged dll, its required platform invoke calls.
Mark Redman
so how can i add GhostScript dll in my project? i am using visual studio 2008 on window vista. i want to add GhostScript dll in my web application.
ankush
As I mentioned in my answer, email me (email on profile page) and I will send you a C# wrapper that will enable you to convert PDF to images. Apart from that you will need to look at the GhostScript documentation to see what the interface is and use pInvoke calls to connect to the Ghostcript dll.
Mark Redman
i have mailed to u ...
ankush
hiii mark.. i used ur code .. but it is giving a error ... that unable to load dll..... please help me lock (typeof(Pdf_2_image.GhostScript)) { GC.Collect(); Pdf_2_image.GhostScript.OutputDevice outputDevice = Pdf_2_image.GhostScript.OutputDevice.jpeg; Pdf_2_image.GhostScript.DeviceOption[] deviceOptions = Pdf_2_image.GhostScript.DeviceOptions.jpg(100); using (Pdf_2_image.GhostScript ghostScript = new Pdf_2_image.GhostScript(@"C:\Program Files\gs\gs8.70\bin")) ; {
ankush
Is there a way to determine the number of pages or even better is there a way to split the pdf with out passing the firstpage or lastpage?
ankush
We use the iTextSharp Library to split/join PDF's
Mark Redman
@ankush: From you previous email, glad to hear you got Ghostscript working..
Mark Redman
+1  A: 

You can check below link

http://www.codeproject.com/KB/library/pdftoimages.aspx

Ravia