如何使用 GhostScript 将 PDF 转换为 TIF?

发布于 2024-10-18 20:43:08 字数 5899 浏览 2 评论 0原文

可能的重复:
将 pdf 文件转换为 tiff 文件的最佳方法 < /p>

我我正在寻找一个免费的库,它允许我将 PDF 文档转换为一个(或多个)TIFF 图像。如果 Tiff 不可行,也可以是其他图像格式。

我读到了有关使用 Ghostscript 执行此操作的方法,但我找不到很好的解释。那么有什么提示如何做到这一点吗?

编辑: 根据评论我使用这个命令执行:

Process.Start("gswin32c", "-dNOPAUSE -q -sDEVICE=tiffg4 -dBATCH -sOutputFile=" + fileName + ".tif " +  fileName + ".pdf");

我看到GhostScript是在命令行中执行的,但是我总是得到一个错误:

  System.ArgumentException was unhandled
  Message=The contact with id '16778241' does not currently exist.
Parameter name: contact
  Source=Microsoft.Surface.Presentation
  ParamName=contact
  StackTrace:
       at Microsoft.Surface.Presentation.Contacts.CheckIfCanBeCapturedOrReleased(Contact contact)
       at Microsoft.Surface.Presentation.Contacts.CaptureContact(Contact contact, IInputElement element)
       at Microsoft.Surface.Presentation.Controls.Primitives.ButtonBaseAdapter.OnContactDown(ContactEventArgs e)
       at Microsoft.Surface.Presentation.Controls.SurfaceButton.OnContactDown(ContactEventArgs e)
       at Microsoft.Surface.Presentation.Controls.SurfaceButton.Microsoft.Surface.Presentation.Controls.IContactEventThunk.OnContactDownThunk(ContactEventArgs e)
       at Microsoft.Surface.Presentation.Controls.InputElementAdapter.OnContactDownThunk(Object sender, ContactEventArgs e)
       at Microsoft.Surface.Presentation.ContactEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at Microsoft.Surface.Presentation.InputSurfaceProviderBase.DoProcessInput(Object obj)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at Prototype_Concept_2.App.Main() in C:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\Prototype_Concept_2\Prototype_Concept_2\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(Assembly 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)
       at System.Threading.ThreadHelper.ThreadStart()

InnerException:

Why this?

Possible Duplicate:
Best way to convert pdf files to tiff files

I'm looking for a free library that allows me to convert a PDF document to a (or several) TIFF images. If Tiff is not possible it can also be other images formats.

I read about a way to do this with Ghostscript, but I couldn't find a good explanation. So any hints how to do that?

EDIT:
According to the comment I use this command to execute:

Process.Start("gswin32c", "-dNOPAUSE -q -sDEVICE=tiffg4 -dBATCH -sOutputFile=" + fileName + ".tif " +  fileName + ".pdf");

I see that GhostScript is executed in the command line, But I always get an error:

  System.ArgumentException was unhandled
  Message=The contact with id '16778241' does not currently exist.
Parameter name: contact
  Source=Microsoft.Surface.Presentation
  ParamName=contact
  StackTrace:
       at Microsoft.Surface.Presentation.Contacts.CheckIfCanBeCapturedOrReleased(Contact contact)
       at Microsoft.Surface.Presentation.Contacts.CaptureContact(Contact contact, IInputElement element)
       at Microsoft.Surface.Presentation.Controls.Primitives.ButtonBaseAdapter.OnContactDown(ContactEventArgs e)
       at Microsoft.Surface.Presentation.Controls.SurfaceButton.OnContactDown(ContactEventArgs e)
       at Microsoft.Surface.Presentation.Controls.SurfaceButton.Microsoft.Surface.Presentation.Controls.IContactEventThunk.OnContactDownThunk(ContactEventArgs e)
       at Microsoft.Surface.Presentation.Controls.InputElementAdapter.OnContactDownThunk(Object sender, ContactEventArgs e)
       at Microsoft.Surface.Presentation.ContactEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at Microsoft.Surface.Presentation.InputSurfaceProviderBase.DoProcessInput(Object obj)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at Prototype_Concept_2.App.Main() in C:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\Prototype_Concept_2\Prototype_Concept_2\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(Assembly 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)
       at System.Threading.ThreadHelper.ThreadStart()

InnerException:

Why this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧竹 2024-10-25 20:43:08

您不能使用 Process.Start(string filename) 重载来提供命令行参数。来自 MSDN:

此重载不允许进程使用命令行参数。如果需要为进程指定一个或多个命令行参数,请使用 Process.Start(ProcessStartInfo) 或 Process.Start(String, String) 重载。
http://msdn.microsoft.com/en-us/library/53ezey2s.aspx

因此,请尝试以下操作:

Process.Start(@"C:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\Prototype_Concept_2\Prototype_Concept_2\bin\Debug\gswin32c", "-dNOPAUSE -q -g300x300 -sDEVICE=tiffg4 -dBATCH -sOutputFile=Report_22_02_2011_21_18.tif Report_22_02_2011_21_18.pdf");

You cannot use the Process.Start(string filename) overload to supply command line parameters. From MSDN:

This overload does not allow command-line arguments for the process. If you need to specify one or more command-line arguments for the process, use the Process.Start(ProcessStartInfo) or Process.Start(String, String) overloads.
http://msdn.microsoft.com/en-us/library/53ezey2s.aspx

So try the following instead:

Process.Start(@"C:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\Prototype_Concept_2\Prototype_Concept_2\bin\Debug\gswin32c", "-dNOPAUSE -q -g300x300 -sDEVICE=tiffg4 -dBATCH -sOutputFile=Report_22_02_2011_21_18.tif Report_22_02_2011_21_18.pdf");

独夜无伴 2024-10-25 20:43:08

您可以发布 Process.Start() 行代码吗?

我猜测找不到文件的错误是由于路径不正确造成的。缺少引号。由于 Visual 和 Studio 中的空间,它会假设“C:\Users\Roflcoptr\Documents\Visual”是目录。

Process.Start(@"\"C:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\Prototype_Concept_2\Prototype_Concept_2\bin\Debug\gswin32c\" -dNOPAUSE -q -g300x300 -sDEVICE=tiffg4 -dBATCH - sOutputFile=Report_22_02_2011_21_18.tif Report_22_02_2011_21_18.pdf");

测试这一点的最佳方法,也许首先启动命令提示符,看看在 Process.Start() 方法中使用它之前是否可以成功运行该命令行称呼。

Can you post up the Process.Start() line of code?

I am guessing the error of file not found is coming from the path being incorrect. That being missing the quotes. Because of the space in visual and studio it would assume that "C:\Users\Roflcoptr\Documents\Visual" is the directory.

Process.Start(@"\"C:\Users\Roflcoptr\Documents\Visual Studio 2008\Projects\Prototype_Concept_2\Prototype_Concept_2\bin\Debug\gswin32c\" -dNOPAUSE -q -g300x300 -sDEVICE=tiffg4 -dBATCH -sOutputFile=Report_22_02_2011_21_18.tif Report_22_02_2011_21_18.pdf");

The best way to test this, maybe to first fire up a command prompt and see if you can run that command line successfully before using it in Process.Start() method call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文