Vb.net 使用ghostscript从ps文件创建pdf
我目前正在尝试以编程方式将一些.ps文件转换为pdf格式-但我正在运行gswin64c,它没有任何可用的教程:( 基本上,到目前为止,我提出了以下观点:Vb.net 使用ghostscript从ps文件创建pdf,vb.net,cmd,ghostscript,Vb.net,Cmd,Ghostscript,我目前正在尝试以编程方式将一些.ps文件转换为pdf格式-但我正在运行gswin64c,它没有任何可用的教程:( 基本上,到目前为止,我提出了以下观点: Dim proc As New Process proc.StartInfo.FileName = My.Settings.GhostscriptPath 'path to the ghostscript bin directory proc.StartInfo.WorkingDirectory = System.IO.Path.GetDir
Dim proc As New Process
proc.StartInfo.FileName = My.Settings.GhostscriptPath 'path to the ghostscript bin directory
proc.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName("c:\test dire\test.ps")
'output umschreiben
proc.StartInfo.RedirectStandardOutput = True
proc.StartInfo.RedirectStandardError = True
proc.StartInfo.UseShellExecute = False
Dim PDfName = System.IO.Path.ChangeExtension("c:\test dire\test.ps", "pdf")
Dim Args As String = String.Format("-dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile='{0}' '{1}'", PDfName, FileName)
proc.StartInfo.Arguments = Args
proc.Start()
proc.WaitForExit()
Dim Output = proc.StandardOutput.ReadToEnd
Dim OutputErrors = proc.StandardError.ReadToEnd
Debug.Print(Output)
Debug.Print(OutputErrors)
它会运行-但ghotscript只会抛出一个“没有这样的文件或目录”错误并退出。要真正运行它,需要做些什么?您的参数字符串在文件名占位符周围使用单引号:
"-dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile='{0}' '{1}'"
但是,单引号在CMD
中不是有效的引号字符,因此该命令很可能失败,因为它正在查找文本文件名'c:\test dire\test.ps'
而不是c:\test dire\test.ps
。请改用双引号:
"-dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=""{0}"" ""{1}"""
必须用另一个双引号对它们进行转义。您只是在CLI下执行,所以不像是在访问GS API之类的。在命令提示符下键入
gswin64c--help
,您将得到一个简短的描述和指向Use.htm
文件的指针,在尝试使用在试图从脚本执行之前,您还可以在命令提示符下测试您的命令。