简体   繁体   中英

Convert PDF to PDF/A to use ghostscript

I try to use the next parameters:

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

My PDFA_def.ps look like this:

%!
% 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

The ISOcoated_v2_300_eci.icc I downloaded when I looked out a solution. I try to use default iccs from gs/lib/iccprofiles/ I try to use -sColorConversionStrategy RGB, CMYK, Gray instead of UseDeviceIndependentColor it does not help. The conversation ends successfully and Ghostscript does not throw any errors. But when I validate the result file in veraPDF I get following report (html file).

Do you have any Idea for me?

UPDATE

Source file

Resut file

One immediate problem is that you have set Ghostscript to produce a PDF/A-2 file, and you are testing for conformance with PDF/A-1, an earlier, more restrictive, standard. You need to either set PDFA=1 or test conformance for PDF/A-2

If you use DeviceIndependentColor you do not need to specify an OutputIntent. If you use RGB, CMYK or Gray you must use an OutptuIntent with an appropriate number of components. I suspect you haven't got this right somewhere along the way.

You have not supplied the input file or the output file, so its impossible to comment on many of the error reports in the HTML file, and the links in the html file can't be followed. I'd suggest you make the source and output files available, and the conformance report for those specific files.

[edit]

using the original file from above, and an srgb.icc profile (you cannot use the Ghostscript profiles as they are version 4 profiles and incompatible with PDF/A-1) along with -sColorConversionStrategy=RGB I produced this PFD/A-1b file. Using the current version of VeraPDF that verifies without complaint using the PDF/A-1b conformance test.

[another edit]

Using current code and this command line:

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

where vertrag.pdf is the original input file and pdfa_def.ps contains:

%!
% 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

(Which is the example supplied with Ghostscript 9.50 modified to use an srgb ICC profile)

I get this file. Executing the PDF/A-2b profile of VeraPDF (version 1.14.8 Greenfield parser) gives green text "PDF is compliant with Validation Profile requirements"

I notice you've cut out the scissor lines in your version of pdfa_def.ps, but you haev NOT added a line like /N 3, as the instructions tell you to. That value must be correct, it must be the number of components in the ICC profile, which is why you have to add it yourself. Or, of course, simply leave the lines that attempt to do it for you in place. If you remove them its up to you to replace them with the correct value.

Note that Ghostscript will emit several warnings, because your original file contains overprint mode set to 1, which is not permitted in PDF/A-2, has a non-printing annotation which is not permitted in PDF/A-2 and a string in the document info is UTF16BE which is also not permitted in PDF/A-2 (or A-1). Because of the PDFACompatibilityPolicy you have selected, these will all be dropped, which may cause the resulting PDF file to render incorrectly.

As an additional experiment I used this command line:

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

Because that uses DeviceIndependentColor, there is no need to execute pdfa_def.ps (We do not need an OutputIntent in the PDF file) and that file also verifies as compatible using the same version of VeraPDF.

For an additional sanity check I used the Acrobat Pro Preflight tool to check the files which also verfified they are compatible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM