如何使用 GhostScript 将 PDF 转换为 TIF?
可能的重复:
将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能使用
Process.Start(string filename)
重载来提供命令行参数。来自 MSDN:因此,请尝试以下操作:
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: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");
您可以发布
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.