Question

Here is the code in question:

MagickNet.InitializeMagick();
ImageMagickNET.Image image = new ImageMagickNET.Image(@"C:\temp.pdf");
image.Quality = 100;
image.CompressType = ImageMagickNET.CompressionType.LosslessJPEGCompression;
image.Write(@"C:\temp.jpg");

I'm fairly certain this code should work, but I get the exceptionally informative exception of: External component has thrown an exception.

This exception is thrown on the line: ImageMagickNET.Image image = new ImageMagickNET.Image(@"C:\temp.pdf");

InnerException: null

StackTrace:

   at Magick.Image.{ctor}(Image* , basic_string<char\,std::char_traits<char>\,std::allocator<char> >* )
   at ImageMagickNET.Image..ctor(String imageSpec)
   at WindowsFormsApplication1.Form1.ReadQRCode(String doc) in C:\Users\me\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs:line 126
   at WindowsFormsApplication1.Form1.seperatePDFsInOrder(String fileName) in C:\Users\me\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs:line 109
   at WindowsFormsApplication1.Form1.InitializeComponent() in C:\Users\me\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs:line 44
   at WindowsFormsApplication1.Form1..ctor() in C:\Users\me\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:line 16
   at WindowsFormsApplication1.Program.Main() in C:\Users\me\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 20
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Anyone have any idea what I might be doing incorrectly?

Was it helpful?

Solution

You seem to declare your image = new as a *.pdf file in your 2nd quoted line. Better try it with c:\tmp.jpg. Or even better c:\temp\tmp.jpg...

ImageMagick applies its 'I want to parse this file as a PDF'-mode if it sees the suffix *.pdf. (It applies its magic file type discovery routines only if the filename doesn't have a suffix.)

Also the user that is running the code possibly cannot write the file c:\tmp.jpg. There could be two reasons:

  1. c:\ as a directory is not writeable for this user.
  2. the file already exists, and can't be overwritten by this user (it may belong to another user).

Lastly, be aware that ImageMagick's capability to process PDFs as input relies on an external 'delegate': it can't do that job itself, it requires a Ghostscript installation on the same host to call it and let it do the job...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top