I´m trying to print a PDF file into any physical printer using GhostScript.
I´m getting an black and white results at the printer.
So, reading the Ghostscript documentation I read about PostScript file. So I´m giving it a try (but without success).
Here´s my C# code:
public bool printGhostScript(string firstPage, string lastPage, string printerName, string pdfFileName)
{
int numberOfCopies = 1;
string ghostScriptPath = @"C:\PrinterBatch\gs9.19\bin\gswin64.exe";
string postScriptPath = @"C:\PrinterBatch\gs9.19\lib\setup.ps";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = " -dSAFER -dFirstPage=" + firstPage + " -dLastPage=" + lastPage + " " + postScriptPath + " -dBATCH -dNOPAUSE -sFONTPATH=C:\\Windows\\Fonts -sPAPERSIZE=letter -sOutputFile=\"\\\\spool\\" + printerName + "\" \"" + pdfFileName + "\" ";
startInfo.FileName = ghostScriptPath;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
Process process = Process.Start(startInfo);
process.WaitForExit(30000);
if (process.HasExited == false)
process.Kill();
return process.ExitCode == 0;
}
As we can see, I´m calling the command to print and setting my PostScript file called "setup.ps".
Here is the code of my Setup.ps:
mark
/BitsPerPixel 4
/NoCancel true
(mswinpr2) finddevice
putdeviceprops
setdevice
The problem I´m getting is this:
Error: /invalidaccess in --setdevice-- Does anyone has an idea to help me?
I just need to print coloured and with quality.
Sorry for the bad english.
EDIT
I forgot to write the command line "/BitsPerPixel 4" at PostScript file. (Already fixed it).
According to the documentation this line is the magical one and makes everything print coloured and with quality.
The command line that is loaded at "arguments" is this:
-dSAFER -dFirstPage=1 -dLastPage=11 C:\PrinterBatch\gs9.19\lib\setup.ps -dBATCH -dNOPAUSE -sFONTPATH=C:\Windows\Fonts -sPAPERSIZE=letter -sOutputFile="\\spool\PDFCreator" "C:\Users\JUNIOR\Desktop\_ABC.pdf"
Before I started to use the PostScript (when I was able to print but only b/w) the command was like this:
-dSAFER -dFirstPage=1 -dLastPage=11 -sDEVICE=mswinpr2 -dBATCH -dNOPAUSE -sFONTPATH=C:\Windows\Fonts -sPAPERSIZE=letter -sOutputFile="\\spool\PDFCreator" "C:\Users\JUNIOR\Desktop\_ABC.pdf"