【问题标题】:Ghostscritpt converted file not view-able in adobe readerGhostscript 转换文件在 adobe reader 中不可见
【发布时间】:2018-09-16 02:41:36
【问题描述】:

我正在尝试通过带有 -sDEVICE=pdfwrite 的幽灵脚本执行 pdf 到 pdfa 的对话。对话成功,但第一页为空白(其余页面都可以);此外,adobe reader 给出错误“处理页面时出错。操作数类型错误。”

命令:

cmd /c C:\app\others\GhostScript\9_21\bin\gswin64.exe -dPDFA=2 -dBATCH -dNOPAUSE -dNOPLATFONTS -dPDFSETTINGS=/printer -sProcessColorModel=DeviceRGB -sDEVICE=pdfwrite -dCompatibilityLevel=1.7 - dOptimize=true -dPDFACompatibilityPolicy=1 -dAutoRotatePages=/None -sOutputFile="1107.pdf" "test1.pdf"

注意:pdfa 文件可以在 pdf-xchange 查看器、chrome 浏览器中读取(也可以是第一页)。问题仅出在 adobe reader 上。

输入pdf:test1.pdf

输出pdfa:1107.pdf

【问题讨论】:

    标签: ghostscript


    【解决方案1】:

    你使用的命令行有很多问题,我会在最后解决。

    首先要说明的是,您应该始终使用当前代码。 9.21 已过期,当前版本为 9.23。当我通过当前版本运行文件时,使用提供的命令行,我在 stderr 上收到了许多警告(或者,因为您使用的是窗口可执行文件,所以在窗口中):

    GPL Ghostscript 9.23 (2018-03-21)
    Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.
    This software comes with NO WARRANTY: see the file PUBLIC for details.
    Processing pages 1 through 12.
    Page 1
    GPL Ghostscript 9.23: Setting Overprint Mode to 1
     not permitted in PDF/A-2, overprint mode not set
    
    Attempting to write a DeviceN space with an inappropriate alternate,
    have you set ColorConversionStrategy ?
    Attempting to write a DeviceN space with an inappropriate alternate,
    have you set ColorConversionStrategy ?
    Attempting to write a DeviceN space with an inappropriate alternate,
    have you set ColorConversionStrategy ?
    Attempting to write a DeviceN space with an inappropriate alternate,
    have you set ColorConversionStrategy ?
    Attempting to write a DeviceN space with an inappropriate alternate,
    have you set ColorConversionStrategy ?
    Attempting to write a DeviceN space with an inappropriate alternate,
    have you set ColorConversionStrategy ?
    Attempting to write a DeviceN space with an inappropriate alternate,
    have you set ColorConversionStrategy ?
    Attempting to write a DeviceN space with an inappropriate alternate,
    have you set ColorConversionStrategy ?
    Attempting to write a DeviceN space with an inappropriate alternate,
    have you set ColorConversionStrategy ?
    Attempting to write a DeviceN space with an inappropriate alternate,
    have you set ColorConversionStrategy ?
    Attempting to write a DeviceN space with an inappropriate alternate,
    have you set ColorConversionStrategy ?
    Attempting to write a DeviceN space with an inappropriate alternate,
    have you set ColorConversionStrategy ?
    >>showpage, press <return> to continue<<
    

    所以这几乎可以告诉你出了什么问题,你还没有设置 ColorConversionStrategy。所有打开文件没有投诉的软件都是不正确的。如果您通过 Ghostscript 将生成的 PDF 文件运行回显示器,它会显示:

    GPL Ghostscript GIT PRERELEASE 9.24 (2018-03-21)
    Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.
    This software comes with NO WARRANTY: see the file PUBLIC for details.
    Processing pages 1 through 1.
    Page 1
       **** Error: Considering object with an invalid number -1 as null.
                   Output may be incorrect.
       **** Error: Considering object with an invalid number -1 as null.
                   Output may be incorrect.
       **** Error reading a content stream. The page may be incomplete.
                   Output may be incorrect.
       **** Error: File did not complete the page properly and may be damaged.
                   Output may be incorrect.
    >>showpage, press <return> to continue<<
    

    更多的戳,通过设置 -dPDFSTOPONERROR 和 -dPDFDEBUG 给出:

    %Resolving: [-1 0]
       **** Error: Considering object with an invalid number -1 as null.
                   Output may be incorrect.
    %Pattern: << /PaintProc {<< >> .pdfpaintproc} /PatternType 2 /.pattern_uses_tran
    sparency false /Matrix [0.000766095 -0.000451741 -0.000306278 -0.000529551 116.3
    78 788.13] /Shading {-1 0 resolveR} >>
    %Resolving: [-1 0]
       **** Error: Considering object with an invalid number -1 as null.
                   Output may be incorrect.
    Error: /typecheck in --makepattern--
    Operand stack:
       --dict:11/19(L)--   --dict:5/13(L)--   --dict:5/13(L)--   --nostringval--   f
    alse   --nostringval--   0.0   --nostringval--   --nostringval--   --dict:5/6(L)
    --   --nostringval--   --nostringval--   --nostringval--   DataSource
    Execution stack:
       %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval-
    -   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   fa
    lse   1   %stopped_push   2015   1   3   %oparray_pop   2014   1   3   %oparray_
    pop   1998   1   3   %oparray_pop   --nostringval--   --nostringval--   2   1
    1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--
      --nostringval--   --nostringval--   %array_continue   --nostringval--   --nost
    ringval--   %loop_continue   --nostringval--   --nostringval--   1958   4   11
     %oparray_pop   --nostringval--   --nostringval--   false   1   %stopped_push
    --nostringval--
    Dictionary stack:
       --dict:984/1684(ro)(G)--   --dict:1/20(G)--   --dict:83/200(L)--   --dict:83/
    200(L)--   --dict:133/256(ro)(G)--   --dict:307/450(ro)(G)--   --dict:33/64(L)--
       --dict:6/9(L)--   --dict:7/20(L)--   --dict:1/1(ro)(G)--   --dict:1/1(ro)(G)-
    -
    Current allocation mode is local
    Last OS error: No such file or directory
    GPL Ghostscript GIT PRERELEASE 9.24: Unrecoverable error, exit code 1
    
    Close this window with the close button on the title bar or the system menu.
    

    因此您可以看到有一个带有无效数字 (-1) 的对象和一个试图使用该对象的着色字典。这是完全违法的。

    现在,原因在于您设置为 pdfwrite 的选项。

    首先要注意,Ghostscript 的 pdfwrite 设备不会“转换”PDF 文件。发生的情况是输入被解释,转换为准备渲染的图形基元,然后发送到渲染线。然而,pdfwrite 设备不会渲染图元,而是将它们重新打包成 PDF 文件。相关的documentation.

    中描述了这种情况的许多后果

    为了创建 PDF/A 文件,输出文件必须遵循一定的规则;它可能不包含 两种 RGB 和 CMYK 颜色,它只能包含一种或另一种。因此,您应该做的第一件事是将 -sColorConversionStrategy 设置为 RGB、CMYK 或 UseDeviceIndependentColor 之一。设置 ProcessColorModel 是不够的。如果您设置 ColorConversionStrategy,则会自动为您设置 ProcessColorModel。这是最初的问题,修复会生成有效的 PDF 文件(但不是有效的 PDF/A 文件)。

    PDF/A 文件还必须包含 ICC 配置文件,即 OutputIntent,除非 PDF 文件仅由灰色或与设备无关的颜色组成。你的命令行不这样做。

    documentation 再次描述了如何创建 PDF/A 文件。

    从基础开始,您设置 -dPDFSETTINGS。在我看来,这是一个非常糟糕的主意,尤其是在尝试创建 PDF/A 文件时。这样做会改变许多设置,除非您绝对确定要将所有这些设置设置为默认设置,否则不应使用它。

    我不会碰-dCompatibilityLevel,pdfwrite 设备会根据它写入输出文件的内容适当地设置它以满足它所需的一致性级别。除非您要向 PDF 文件(使用 pdfmarks)添加需要更高级别的结构,否则所有这些都会限制文件由更新版本的 Acrobat 打开。

    我不会使用 -dOptimize,除非是因为它没有任何事情!如果你阅读了文档,那么在 Distiller params 下的注释 0 说明这可以设置和查询,但没有任何效果。

    pdfwrite 等价物是 -dFastWebView,但我仍然不会使用它,因为它几乎没有用,最多只能加快第一页的加载速度,而且只有在 PDF 消费者使用它时,大多数人不会。

    【讨论】:

    • 感谢@KenS 的详细回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多