When I use ghostscript in windows cmd with my setup.ps postscript file it prints my pdfs perfectly.
setup.ps
mark
/OutputFile (%printer%HP LaserJet 1018)
/BitsPerPixel 1
/NoCancel false
/UserSettings
<<
/DocumentName(document)
/MaxResolution 360
>>
(mswinpr2)finddevice
putdeviceprops
setdevice
<<
/BeginPage {10 -55 translate}
>>
setpagedevice
CommandLine
start /d "C:\Program Files (x86)\gs\gs9.19\bin" gswin32.exe -sOutputFile="%printer%HP LaserJet 1018" -dBATCH -dNOPAUSE -dFIXEDMEDIA setup.ps a.pdf
(I don't know why it needs sOutputFile in setup.ps and in commandline but it doesn't work otherwise)
Now when I put the same switches in my C# project which uses Ghostscript.NET wrapper.
private static void CreateSetupPsFile(string printername)
{
const string Translationstring = @"{10 -15 translate}";
string ps = $@"
mark
/OutputFile (%printer%{printername})
/BitsPerPixel 1
/NoCancel false % don't show the cancel dialog
/UserSettings
<<
/DocumentName(document) % name for the Windows spooler
/MaxResolution 360
>>
(mswinpr2)finddevice % select the Windows device driver
putdeviceprops
setdevice
<<
/PageOffset [30 -30]
>>
setpagedevice";
File.WriteAllText("setup.ps", ps);
}
private static void PrintA4(string pdfFileName, PrinterSettings printerSettings)
{
using (var processor = new GhostscriptProcessor(GsDll))
{
CreateSetupPsFile(printerSettings.PrinterName);
var switches = new List<string>
{
$"-sOutputFile=\"%printer%{printerSettings.PrinterName}\"",
@"-dBATCH",
@"-dNOPAUSE",
@"-dFixedMedia",
"setup.ps",
"-f",
pdfFileName
};
processor.StartProcessing(switches.ToArray(), null);
}
}
It totally ignores everything in the setup.ps file. Does anyone know why ? It just ignores and doesn't say what's wrong
Thank you in advance
Update
I managed to run some poscript... Apparently the wrapper needs the postscript to be given like that:
var switches = new List<string>
{
@"-dBATCH",
@"-dNOPAUSE",
@"-sDEVICE=mswinpr2",
$@"-sOutputFile=%printer%{printerSettings.PrinterName}",
"-c",
$"<</BeginPage {translateString}>> setpagedevice",
"-f",
pdfFileName
};
processor.StartProcessing(switches.ToArray(), null);
Not like that:
var switches = new List<string>
{
@"-dBATCH",
@"-dNOPAUSE",
@"-sDEVICE=mswinpr2",
$@"-sOutputFile=%printer%{printerSettings.PrinterName}",
$"-c <</BeginPage {translateString}>> setpagedevice -f",
pdfFileName
};
processor.StartProcessing(switches.ToArray(), null);
It's just unbelievable.