Java – ghost4j / ghostscript – error 100 when trying to embed fonts in PDF
I have PDF with reference font, and I want to use ghost4j to output PDF with embedded font
public void execute() { Ghostscript gs = Ghostscript.getInstance(); String[] cmdStr={ "-dNOPAUSE","-dBATCH","-dCompatibilityLevel=1.4","-dPDFSETTINGS=/prepress","-dSAFER","-dNOPLATFONTS","-sDEVICE=display","-sPAPERSIZE=letter","-I","C:\\WINNT\\Fonts\\;C:\\Program Files\\gs\\gs9.05\\lib\\;C:\\Program Files\\gs\\gs9.05\\bin\\;","-dSubsetFonts=true","-dEmbedAllFonts=true","-sFONTPATH=C:\\WINNT\\Fonts","-sOutputFile=",outputPath,"-c",".setpdfwrite","-f",inputPath }; try { gs.initialize(cmdStr); gs.exit(); } catch (GhostscriptException e) { System.out.println("ERROR: " + e.getMessage()); e.printStackTrace(); }
When running any PDF, I receive the following error:
ERROR: Cannot initialize Ghostscript interpreter. Error code is -100
When running on the command line, the parameters work properly
gswin32c.exe -dNOPAUSE -dBATCH -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dSafer -NOPLATFONTS -sDEVICE=pdfwrite -sPAPERSIZE=letter -dSubsetFonts=true -dEmbedAllFonts=true -sFONTPATH=C:\\WINNT\\Fonts -sOutputFile=c:\out.pdf -f c:\test.pdf
Follow up:
>Ghostscript has the right to write to C:. > I deleted all switches except outputpath, "– F" and inputpath, and I still got the error > after inputpath, I deleted the comma at the end of cmdstr
Notes:
>I'm trying to get a callback
Solution
There is a comma after your inputpath variable This is invalid Java syntax
I use ghost script to generate PCL files from PDF in production Java applications I use Java Lang. runtime class to execute ghostscript executable, so I can't directly provide suggestions for ghost4j
I suspect the problem is that the API does not know the location of the support files Try to pass the full path of font, lib and bin locations, as shown below
"-Ic:\Program Files (x86)\gs\fonts\;c:\Program Files (x86)\gs\lib\;c:\Program Files (x86)\gs\bin\;"