I am trying to produce "c:\output.pdf" from existed and well formed "output.ps" file with VB.NET and shell to gswin32c.exe which is in current directory.
But I obviously can't write shell command properly:
If LCase(p_printer).Contains("ghostscript") Then
' to not show old one
IO.File.Delete(OutputPDF)
If IO.File.Exists(InputPS) Then
Dim commandString As String = """gswin32c.exe -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dQUIET -sOUTPUTFILE=" & OutputPDF & " " & InputPS & """"
Debug.Print(commandString)
Shell(commandString, AppWinStyle.NormalFocus)
If IO.File.Exists(OutputPDF) And bln_showpdf Then
'show PDF
Start(OutputPDF)
End If
Else
MsgBox(InputPS + " do NOT exists.", MsgBoxStyle.Critical)
End If
End If
From cmd window those command regularly produce "output.pdf"
What is incorrect and how to get it working?
Dim InputPS as String = "C:\Temp\output.ps" 'must use 8.3 file naming convention
Dim OutputPDF as String = "C:\Temp\output.pdf" 'must use 8.3 file naming convention
Dim CommandString as String = "C:\GS\gswin32c.exe -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dQUIET -sOUTPUTFILE=" & OutputPDF & " " & InputPS
Debug.Print(CommandString)
Shell(CommandString, AppWinStyle.NormalFocus)
Actually the command string doesn't need quotation marks, I tested it without them. You must use 8.3 file naming convention though. Note that in this code the input and output filenames do not start or end with quotation marks; That is why you must use 8.3 file naming convention for this to succeed. And no spaces in the file names or paths.
Your problem is that it can't find the file; relying on the currently active directory is not a good practice as it can cause problems. The solution is to provide full path and file name with no spaces and using 8.3 file naming convention for both path and file name.
Also make sure that GSDLL32.DLL is in the same folder as GSWin32C.exe.