当我在windows cmd中使用ghostscript和我的setup.ps postscript文件时,它可以完美地打印我的pdf文件。
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}
>>
setpagedeviceCommandLine
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...显然,包装器需要这样的postscript:
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);这太不可思议了。
发布于 2016-09-08 20:38:58
你怎么知道它忽略了setup.ps中的内容?
在PostScript程序中添加一些调试程序,例如
(Inside setup.ps) == flush我看到的第一件也是最明显的一件事是,你认为setup.ps包含:
<<
/BeginPage {10 -55 translate}
>>
setpagedevice然而,您用于创建setup.ps的代码包含:
<<
/PageOffset [30 -30]
>>
setpagedevice";显然,这些代码并不相同,这让我怀疑您是否正在执行您认为自己正在执行的PostScript代码。
我对你上一个问题的回答你做得怎么样?
添加一个示例,在不使用setup.ps或非标准扩展的情况下执行所有繁琐的setup.ps内容。
首先,你不需要使用finddevice、putdeviceprops或setdevice。只需在命令行上设置设备并使用setpagedevice设置属性即可。这是标准的PostScript和设备的配置方式。Ghostscript可能会在幕后使用其非标准内容,但您不必担心这一点。
所以就像这样:
gswin32 -sDEVICE=mswinpr2 -sOutputFile=%printer%PrinterName -c "<</BitsPerPixel 1 /NoCancel false /DocumentName (dummy) /MaxResolution 360 /BeginPage {10 10 translate}>> setpagedevice" -f PDF.pdf因为您没有使用finddevice/putdeviceprops/setdevice,所以不需要尝试设置两次OutputFile。我假设您确实想要BeginPage,但不想要PageOffset。我不知道你是否真的想要所有这些特定于设备的设置,因为我不知道你使用的是哪种打印机,所以我就把它们留在那里了。
显然我不能测试这个,因为我没有你的打印机,但它应该可以工作。所有在setup.ps中的混乱都是坏消息,如果可能我会尽量避免它。
https://stackoverflow.com/questions/39388178
复制相似问题