将PDF转换为PDF/A以使用ghostscript

问题描述 投票:0回答:1

我尝试使用下一个参数:

          '-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

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

你对我有什么想法吗?

更新

源文件

结果文件

pdf ghostscript pdfa
1个回答
6
投票

一个迫在眉睫的问题是,您已将 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

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

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

我注意到您已经剪掉了 pdfa_def.ps 版本中的剪刀线,但您NOT添加了像 /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),并且该文件also 使用相同版本的 VeraPDF 验证为兼容。

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

© www.soinside.com 2019 - 2024. All rights reserved.