我正在尝试将带有RedMon的打印机.PS文件重定向到我的Java代码。
RedMon端口配置:
重定向到程序: C:\ Program Files \ Java \ jre1.8.0_111 \ bin \ java.exe
参数: -jar c:\ dist \ JavaApplication5.jar --stdin
和Java代码:
public class JavaAplication5 {
public static void main(String[] args) throws FileNotFoundException {
BasicConfigurator.configure(); //log4j
System.setProperty("jna.library.path", "C:\\dist\\"); //fix path to gsdll
FileInputStream file = new FileInputStream(args[0]);
Ghostscript gs = Ghostscript.getInstance();
String[] gsArgs = new String[10];
gsArgs[0] = "-ps2pdf";
gsArgs[1] = "-dNOPAUSE";
gsArgs[2] = "-dBATCH";
gsArgs[3] = "-dSAFER";
gsArgs[4] = "-sDEVICE=pdfwrite";
gsArgs[5] = "-sOutputFile=output.pdf";
gsArgs[6] = "-c";
gsArgs[7] = ".setpdfwrite";
gsArgs[8] = "-f";
gsArgs[9] = String.format(" %s ", file) ;
try {
gs.initialize(gsArgs);
gs.exit();
} catch (GhostscriptException e) {
JOptionPane.showMessageDialog(null, "ERROR: " + e.getMessage());
}
}
}
我怎样才能让它发挥作用?
答案 0 :(得分:0)
因此,如果我正确阅读,您已设置RedMon将发送到端口的数据发送到Java应用程序。
然后系统调用Ghostscript(使用ps2pdf脚本)并告诉它从stdin读取。
但是Ghostscript stdin不是你的Java程序的stdin,除非我误解了Java的某些方面。
我希望当你分叉Ghostscript实例时,应用程序获得自己的stdin,这与与Java程序关联的stdin不同。
最好的办法是将Java程序的输入写入文件,完成后,在文件上执行Ghostscript。