首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将PDF转换为PDF/A以使用幽灵脚本

将PDF转换为PDF/A以使用幽灵脚本
EN

Stack Overflow用户
提问于 2019-11-12 07:29:30
回答 1查看 3.9K关注 0票数 1

我尝试使用下面的参数:

代码语言:javascript
复制
          '-dPDFA=2 ' +
          '-dBATCH ' +
          '-DNOSAFER ' +
          '-dNOPAUSE ' +
          '-sColorConversionStrategy=UseDeviceIndependentColor ' +
          '-sDEVICE=pdfwrite ' +
          '-dPDFACompatibilityPolicy=1 ' +
          '-o ./temp.pdf' +
          './PDFA_def.ps' +
          './out/temp.pdf'

我的PDFA_def.ps看起来是这样的:

代码语言:javascript
复制
%!
% 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/iccprofile/的默认iccs /我尝试使用-sColorConversionStrategy RGB、CMYK、Gray而不是UseDeviceIndependentColor --它没有帮助。对话成功结束,Ghostscript不会抛出任何错误。但是,当我在veraPDF中验证结果文件时,我得到了下面的报告 (html文件)。

你对我有什么想法吗?

更新

源文件

Resut文件

EN

回答 1

Stack Overflow用户

发布于 2019-11-12 08:27:26

一个直接的问题是,您已经将Ghostscript设置为生成一个PDF/A2文件,并且您正在测试是否符合PDF/A-1,这是一个更早、更严格的标准。您需要为PDF/A-2设置PDFA=1或测试一致性

如果使用DeviceIndependentColor,则不需要指定OutputIntent。如果使用RGB、CMYK或Gray,则必须使用具有适当数量的组件的OutptuIntent。我怀疑你在这条路上搞错了。

您没有提供输入文件或输出文件,因此不可能对HTML文件中的许多错误报告进行注释,而且html文件中的链接也无法遵循。我建议您提供源文件和输出文件,以及这些特定文件的一致性报告。

编辑

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

另一个编辑

使用当前代码和此命令行:

代码语言:javascript
复制
gs -dNOSAFER -sDEVICE=pdfwrite -dPDFA=2 -sColorConversionStrategy=RGB -dPDFACompatibilityPolicy=1 -sOutputFile=pdfa2.pdf pdfa_def.ps "vertrag.pdf"

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

代码语言:javascript
复制
%!
% 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配置文件的示例)

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

我注意到您已经在您的pdfa_def.ps版本中删除了剪刀行,但是您已经按照说明所示,添加了一个类似于/N 3的行,而不是。这个值必须是正确的,它必须是ICC配置文件中组件的数量,这就是为什么您必须自己添加它。或者,当然,只需将试图为您做这件事的行放在适当的位置。如果您删除它们,则由您来用正确的值替换它们。

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

作为另一个实验,我使用了以下命令行:

代码语言:javascript
复制
gs -dNOSAFER -sDEVICE=pdfwrite -dPDFA=2 -sColorConversionStrategy=UseDeviceIndependentColor -dPDFACompatibilityPolicy=1 -sOutputFile=pdfa2.pdf "vertrag.pdf"

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

对于额外的健全检查,我使用Acrobat飞行前工具来检查文件,这也验证了它们是兼容的。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58813905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档