簡體   English   中英

將 PDF 轉換為 PDF/A 以使用 ghostscript

[英]Convert PDF to PDF/A to use ghostscript

我嘗試使用下一個參數:

          '-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 中驗證結果文件時,我得到以下報告(html 文件)。

你對我有什么想法嗎?

更新

源文件

結果文件

一個直接的問題是您已將 Ghostscript 設置為生成 PDF/A-2 文件,並且您正在測試與 PDF/A-1 的一致性,這是一種較早的、更具限制性的標准。 您需要設置 PDFA=1 或測試 PDF/A-2 的一致性

如果使用 DeviceIndependentColor,則不需要指定 OutputIntent。 如果使用 RGB、CMYK 或灰色,則必須使用具有適當數量組件的 OutptuIntent。 我懷疑您在此過程中的某個地方沒有做到這一點。

您沒有提供輸入文件或 output 文件,因此無法評論 HTML 文件中的許多錯誤報告,並且無法跟蹤 html 文件中的鏈接。 我建議您提供源文件和 output 文件,以及這些特定文件的一致性報告。

[編輯]

使用上面的原始文件和 srgb.icc 配置文件(您不能使用 Ghostscript 配置文件,因為它們是版本 4 配置文件並且與 PDF/A-1 不兼容)以及 -sColorConversionStrategy=RGB 我制作了這個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 提供的示例)

我得到這個文件。 執行 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 工具來檢查文件,這些文件也驗證了它們是兼容的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM