【问题标题】:Convert PDF to PDF/A to use ghostscript将 PDF 转换为 PDF/A 以使用 ghostscript
【发布时间】:2020-03-07 21:08:43
【问题描述】:

我尝试使用下一个参数:

          '-dPDFA=2 ' +
          '-dBATCH ' +
          '-DNOSAFER ' +
          '-dNOPAUSE ' +
          '-sColorConversionStrategy=UseDeviceIndependentColor ' +
          '-sDEVICE=pdfwrite ' +
          '-dPDFACompatibilityPolicy=1 ' +
          '-o ./temp.pdf' +
          './PDFA_def.ps' +
          './out/temp.pdf'

我的 PDFA_def.ps 如下所示:

%!
% This is a sample prefix file for creating a PDF/A document.
% Users should modify entries marked with "Customize".
% This assumes an ICC profile resides in the file (srgb.icc),
% in the current directory unless the user modifies the corresponding line below.

% Define entries in the document Info dictionary :


% Define an ICC profile :
/ICCProfile (/Users/user/nestjs/ISOcoated_v2_300_eci.icc) % Customise
def

[/_objdef {icc_PDFA} /type /stream /OBJ pdfmark

%% This code attempts to set the /N (number of components) key for the ICC colour space.
%% To do this it checks the ColorConversionStrategy or the device ProcessColorModel if
%% ColorConversionStrategy is not set.
%% This is not 100% reliable. A better solution is for the user to edit this and replace
%% the code between the ---8<--- lines with a simple declaration like:
%%   /N 3
%% where the value of N is the number of components from the profile defined in /ICCProfile above.
%%
[{icc_PDFA}
<<
>> /PUT pdfmark
[{icc_PDFA} ICCProfile (r) file /PUT pdfmark

% Define the output intent dictionary :

[/_objdef {OutputIntent_PDFA} /type /dict /OBJ pdfmark
[{OutputIntent_PDFA} <<
  /Type /OutputIntent               % Must be so (the standard requires).
  /S /GTS_PDFA1                     % Must be so (the standard requires).
  /DestOutputProfile {icc_PDFA}     % Must be so (see above).
  /OutputConditionIdentifier (ISO Coated v2 300% (ECI)) % Customize
>> /PUT pdfmark
[{Catalog} <</OutputIntents [ {OutputIntent_PDFA} ]>> /PUT pdfmark

我在寻找解决方案时下载的 ISOcoat_v2_300_eci.icc。 我尝试使用 gs/lib/iccprofiles/ 中的默认 iccs 我尝试使用 -sColorConversionStrategy RGB, CMYK, Gray 而不是 UseDeviceIndependentColor 它没有帮助。 对话成功结束,Ghostscript 不会抛出任何错误。但是当我在 veraPDF 中验证结果文件时,我得到了关注 report(html 文件)。

你对我有什么想法吗?

更新

Source file

Resut file

【问题讨论】:

    标签: pdf ghostscript pdfa


    【解决方案1】:

    一个直接的问题是您已将 Ghostscript 设置为生成 PDF/A-2 文件,并且您正在测试与 PDF/A-1 的一致性,这是一个较早的、更具限制性的标准。您需要设置 PDFA=1 或测试 PDF/A-2 的一致性

    如果您使用 DeviceIndependentColor,则无需指定 OutputIntent。如果使用 RGB、CMYK 或灰色,则必须使用具有适当数量组件的 OutptuIntent。我怀疑您在此过程中的某个地方没有正确解决此问题。

    您没有提供输入文件或输出文件,因此无法对HTML文件中的许多错误报告进行评论,并且无法访问html文件中的链接。我建议您提供源文件和输出文件,以及这些特定文件的一致性报告。

    [编辑]

    使用上面的原始文件和 srgb.icc 配置文件(您不能使用 Ghostscript 配置文件,因为它们是版本 4 配置文件并且与 PDF/A-1 不兼容)以及 -sColorConversionStrategy=RGB 我生成了this PFD /A-1b 文件。使用当前版本的 VeraPDF,该版本使用 PDF/A-1b 一致性测试进行验证且无异议。

    [另一个编辑]

    使用当前代码和这个命令行:

    gs -dNOSAFER -sDEVICE=pdfwrite -dPDFA=2 -sColorConversionStrategy=RGB -dPDFACompatibilityPolicy=1 -sOutputFile=pdfa2.pdf pdfa_def.ps "vertrag.pdf"
    

    其中 vertrag.pdf 是原始输入文件,pdfa_def.ps 包含:

    %!
    % This is a sample prefix file for creating a PDF/A document.
    % Users should modify entries marked with "Customize".
    % This assumes an ICC profile resides in the file (srgb.icc),
    % in the current directory unless the user modifies the corresponding line below.
    
    % Define entries in the document Info dictionary :
    [ /Title (Title)       % Customise
      /DOCINFO pdfmark
    
    % Define an ICC profile :
    /ICCProfile (/temp/srgb.icc) % Customise
    def
    
    [/_objdef {icc_PDFA} /type /stream /OBJ pdfmark
    
    %% This code attempts to set the /N (number of components) key for the ICC colour space.
    %% To do this it checks the ColorConversionStrategy or the device ProcessColorModel if
    %% ColorConversionStrategy is not set.
    %% This is not 100% reliable. A better solution is for the user to edit this and replace
    %% the code between the ---8<--- lines with a simple declaration like:
    %%   /N 3
    %% where the value of N is the number of components from the profile defined in /ICCProfile above.
    %%
    [{icc_PDFA}
    <<
    %% ----------8<--------------8<-------------8<--------------8<----------
      systemdict /ColorConversionStrategy known {
        systemdict /ColorConversionStrategy get cvn dup /Gray eq {
          pop /N 1 false
        }{
          dup /RGB eq {
            pop /N 3 false
          }{
            /CMYK eq {
              /N 4 false
            }{
              (ColorConversionStrategy not a device space, falling back to ProcessColorModel, output may not be valid PDF/A.)=
              true
            } ifelse
          } ifelse
        } ifelse
      } {
        (ColorConversionStrategy not set, falling back to ProcessColorModel, output may not be valid PDF/A.)=
        true
      } ifelse
    
      {
        currentpagedevice /ProcessColorModel get
        dup /DeviceGray eq {
          pop /N 1
        }{
          dup /DeviceRGB eq {
            pop /N 3
          }{
            dup /DeviceCMYK eq {
              pop /N 4
            } {
              (ProcessColorModel not a device space.)=
              /ProcessColorModel cvx /rangecheck signalerror
            } ifelse
          } ifelse
        } ifelse
      } if
    %% ----------8<--------------8<-------------8<--------------8<----------
    
    >> /PUT pdfmark
    [{icc_PDFA} ICCProfile (r) file /PUT pdfmark
    
    % Define the output intent dictionary :
    
    [/_objdef {OutputIntent_PDFA} /type /dict /OBJ pdfmark
    [{OutputIntent_PDFA} <<
      /Type /OutputIntent               % Must be so (the standard requires).
      /S /GTS_PDFA1                     % Must be so (the standard requires).
      /DestOutputProfile {icc_PDFA}     % Must be so (see above).
      /OutputConditionIdentifier (sRGB) % Customize
    >> /PUT pdfmark
    [{Catalog} <</OutputIntents [ {OutputIntent_PDFA} ]>> /PUT pdfmark
    

    (这是修改为使用 srgb ICC 配置文件的 Ghostscript 9.50 提供的示例)

    我得到this 文件。执行 VeraPDF(版本 1.14.8 Greenfield 解析器)的 PDF/A-2b 配置文件会给出绿色文本“PDF 符合验证配置文件要求”

    我注意到您已经在您的 pdfa_def.ps 版本中剪掉了剪刀行,但是您没有添加了 /N 3 之类的行,正如说明告诉您的那样。该值必须正确,它必须是 ICC 配置文件中的组件数,这就是您必须自己添加它的原因。或者,当然,只需将尝试为您执行此操作的行留在原处。如果您删除它们,则由您自己替换为正确的值。

    请注意,Ghostscript 会发出多个警告,因为您的原始文件包含设置为 1 的叠印模式,这在 PDF/A-2 中是不允许的,有一个在 PDF/A-2 中不允许的非打印注释,并且文档信息中的字符串是 UTF16BE,这在 PDF/A-2(或 A-1)中也是不允许的。由于您选择了 PDFACompatibilityPolicy,这些都将被丢弃,这可能会导致生成的 PDF 文件无法正确呈现。

    作为一个额外的实验,我使用了这个命令行:

    gs -dNOSAFER -sDEVICE=pdfwrite -dPDFA=2 -sColorConversionStrategy=UseDeviceIndependentColor -dPDFACompatibilityPolicy=1 -sOutputFile=pdfa2.pdf "vertrag.pdf"
    

    因为使用了 DeviceIndependentColor,所以不需要执行 pdfa_def.ps(我们不需要 PDF 文件中的 OutputIntent)并且该文件使用相同版本的 VeraPDF 验证为兼容。

    为了进行额外的完整性检查,我使用了 Acrobat Pro Preflight 工具来检查文件,这些文件也验证了它们是兼容的。

    【讨论】:

    • 我更新了我的问题。添加源文件和结果文件
    • 嗯,正如我上面所说,第一件事是您正在生成 PDF/A-2 文件,并验证与 PDF/A-1 的一致性,这根本行不通。如果您想要 PDF/A-1 文件,则需要设置 -dPDFA=1。另一方面,如果您想要 PDF/A-2 文件,则需要告诉 VeraPDF 测试与 PDF/A-2 的一致性。
    • 我使用 PDFA-2 配置进行了测试,得到了相同的结果。我稍后更新了这个问题并添加了一个带有 PDFA-2 配置的 vera 报告。谢谢你的回答。
    猜你喜欢
    • 2016-06-15
    • 2023-04-08
    • 1970-01-01
    • 2010-12-12
    • 2014-11-20
    • 2019-04-02
    • 2017-02-21
    • 2022-01-19
    • 1970-01-01
    相关资源
    最近更新 更多