2012-04-23 134 views
4

我使用引用字體的PDF,我想使用Ghost4J輸出包含嵌入字體的PDF。Ghost4J/Ghostscript - 嘗試將字體嵌入PDF時出錯100

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(); 
    } 

在運行任何PDF我得到以下錯誤:

ERROR: Cannot initialize Ghostscript interpreter. Error code is -100 

在命令行參數正常工作運行。

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 

後續處理:

  • GhostScript的具有寫權限C :.
  • 我已刪除了所有的開關,除了outputPath, 「F」,inputPath我仍然得到錯誤
  • 刪除逗號在cmdStr結束inputPath

注:

  • 我正在努力獲得回調
+0

我不知道Ghost4J什麼,但是....這些參數'-ps2pdf'和'-psconv'不看熟悉我Ghostscript的命令行。另外,在代碼示例的cmdStr中,我沒有看到可以在Windows上工作的'gswin32c.exe'的調用(僅適用於Unix的'gs')... – 2012-04-23 19:14:11

+0

Ghost4J只是C++ Ghostscript的Java包裝器碼。 http://ghost4j.sourceforge.net/ – eabraham 2012-04-23 19:29:46

+0

我猜得這麼多......但是你確定你從Java代碼中調用Ghostscript的方式是正確的嗎? – 2012-04-23 20:35:07

回答

1

您的inputPath變量後面有逗號。這是無效的Java語法。

我在生產Java應用程序中使用ghostscript從PDF生成PCL文件。我使用java.lang.Runtime類來執行Ghostscript可執行文件,因此我無法直接爲Ghost4J提供建議。

我懷疑問題是api不知道支持文件的位置。嘗試傳遞字體,lib和bin位置的完整路徑,如下所示。

"-Ic:\Program Files (x86)\gs\fonts\;c:\Program Files (x86)\gs\lib\;c:\Program Files (x86)\gs\bin\;" 
+0

你是對的關於逗號,但我仍然收到錯誤消息。 – eabraham 2012-05-07 20:21:06