当我在 windows cmd 中使用带有 setup.ps postscript 文件的 ghostscript 时,它会完美地打印我的 pdf。
安装程序.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
命令行
start /d "C:\Program Files (x86)\gs\gs9.19\bin" gswin32.exe -sOutputFile="%printer%HP LaserJet 1018" -dBATCH -dNOPAUSE -dFIXEDMEDIA setup.ps a.pdf
(我不知道为什么它在 setup.ps 和命令行中需要 sOutputFile 但否则它不起作用)
现在,当我在使用 Ghostscript.NET 包装器的 C# 项目中放置相同的开关时。
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);
}
}
它完全忽略了 setup.ps 文件中的所有内容。有谁知道为什么?它只是忽略并且不说出了什么问题
先感谢您
更新
我设法运行了一些 poscript... 显然,包装器需要像这样给出后记:
var switches = new List<string>
{
@"-dBATCH",
@"-dNOPAUSE",
@"-sDEVICE=mswinpr2",
$@"-sOutputFile=%printer%{printerSettings.PrinterName}",
"-c",
$"<</BeginPage {translateString}>> setpagedevice",
"-f",
pdfFileName
};
processor.StartProcessing(switches.ToArray(), null);
不是这样的:
var switches = new List<string>
{
@"-dBATCH",
@"-dNOPAUSE",
@"-sDEVICE=mswinpr2",
$@"-sOutputFile=%printer%{printerSettings.PrinterName}",
$"-c <</BeginPage {translateString}>> setpagedevice -f",
pdfFileName
};
processor.StartProcessing(switches.ToArray(), null);
这简直令人难以置信。