簡體   English   中英

為什么我不能用ImageMagickNet打開PDF文件?

[英]Why can't I open a PDF file with ImageMagickNet?

這是有問題的代碼:

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

我相當肯定這段代碼應該可以工作,但是我得到了一個非常有用的例外: External component has thrown an exception.

拋出此異常: ImageMagickNET.Image image = new ImageMagickNET.Image(@"C:\\temp.pdf");

InnerException:null

堆棧跟蹤:

   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()

任何人都知道我可能做錯了什么?

您似乎在第二個引用行中聲明了您的image = new作為* .pdf文件。 最好用c:\\tmp.jpg 或者甚至更好的c:\\temp\\tmp.jpg ......

如果ImageMagick看到后綴* .pdf,則應用其“我想將此文件解析為PDF”模式。 (僅當文件名沒有后綴時,它才應用其魔術文件類型發現例程。)

運行代碼的用戶也可能無法寫入文件c:\\tmp.jpg 可能有兩個原因:

  1. c:\\因為該用戶無法寫入目錄。
  2. 該文件已存在,並且不能被該用戶覆蓋(它可能屬於另一個用戶)。

最后,請注意ImageMagick將PDF作為輸入進行處理的能力依賴於外部“委托”:它本身無法完成該作業,它需要在同一主機上安裝Ghostscript才能調用它並讓它完成工作......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM