これまで PostScript を使用したことがありませんでした...そして、次のようなツールを置き換える必要があります。
- 文字列をポストスクリプトに変換します
- Postscript ファイルに基づいて pdf ファイルを生成します (完了)。
私の問題は次のとおりです。ステップ1を達成する方法がわかりません。ちなみに、ステップ(2)で行った方法と同様の方法で行うことをお勧めします。
パラメータを置き換えるだけでよいのだろうかと思っていましたが、どうすればよいでしょうか。助けていただけませんか?
項目 (2) のコードは次のとおりです。
public byte[] convertPostScriptToPDF() throws IOException {
//get Ghostscript instance
Ghostscript gs = Ghostscript.getInstance();
File file= new File (this.getClass().getResource( "/resources/employer_report_last_page2.ps").getFile());//(Config.EMP_REPORT.REPORT_LAST_PAGE_STORE_PATH);
File pdfGenerated = File.createTempFile("output", "pdf");
System.out.println("Path for temp file -> " + pdfGenerated.getAbsolutePath());
//prepare Ghostscript interpreter parameters
//refer to Ghostscript documentation for parameter usage
String[] gsArgs = new String[10];
gsArgs[0] = "-ps2pdf";
gsArgs[1] = "-dNOPAUSE";
gsArgs[2] = "-dBATCH";
gsArgs[3] = "-dSAFER";
gsArgs[4] = "-sDEVICE=pdfwrite";
// gsArgs[5] = "-sOutputFile=output2.pdf";//output file name
gsArgs[5] = "-sOutputFile=" + pdfGenerated.getAbsolutePath();
// gsArgs[5] = "-sOutputFile=" + file.getAbsolutePath();
gsArgs[6] = "-c";
gsArgs[7] = ".setpdfwrite";
gsArgs[8] = "-f";
// gsArgs[9] = "input.ps";//input file name
gsArgs[9] = file.getAbsolutePath();//input file name
//execute and exit interpreter
try {
gs.initialize(gsArgs);
gs.exit();
} catch (GhostscriptException e) {
System.out.println("ERROR: " + e.getMessage());
}
FileInputStream fis = new FileInputStream(pdfGenerated);
return IOUtils.toByteArray(fis);
}
前もって感謝します!