加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Ghost4J / Ghostscript – 尝试将字体嵌入PDF时获得错误

发布时间:2020-12-15 02:33:35 所属栏目:Java 来源:网络整理
导读:我有带引用字体的PDF,我想使用Ghost4J输出包含嵌入字体的PDF. public void execute() { Ghostscript gs = Ghostscript.getInstance(); String[] cmdStr={ "-dNOPAUSE","-dBATCH","-dCompatibilityLevel=1.4","-dPDFSETTINGS=/prepress","-dSAFER","-dNOPLATF
我有带引用字体的PDF,我想使用Ghost4J输出包含嵌入字体的PDF.

public void execute() {
    Ghostscript gs = Ghostscript.getInstance();
    String[] cmdStr={
        "-dNOPAUSE","-dBATCH","-dCompatibilityLevel=1.4","-dPDFSETTINGS=/prepress","-dSAFER","-dNOPLATFONTS","-sDEVICE=display","-sPAPERSIZE=letter","-I","C:WINNTFonts;C:Program Filesgsgs9.05lib;C:Program Filesgsgs9.05bin;","-dSubsetFonts=true","-dEmbedAllFonts=true","-sFONTPATH=C:WINNTFonts","-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:WINNTFonts -sOutputFile=c:out.pdf -f c:test.pdf

随访:

> GhostScript有权写入C:.
>我删除了除outputPath,“ – f”,inputPath之外的所有开关,我仍然得到错误
>在inputPath之后删除了cmdStr末尾的逗号

笔记:

>我正在努力获得回调

解决方法

你的inputPath变量后面有一个逗号.这是无效的Java语法.

我在生产java应用程序中使用ghostscript从PDF生成PCL文件.我使用java.lang.Runtime类来执行Ghostscript可执行文件,因此我无法直接为Ghost4J提供建议.

我怀疑问题是api不知道支持文件的位置.尝试传递字体,lib和bin位置的完整路径,如下所示.

"-Ic:Program Files (x86)gsfonts;c:Program Files (x86)gslib;c:Program Files (x86)gsbin;"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读