title: Convert PDF files to PDF/A via Ghostscript
body: <p>I'd like to convert arbitrary PDF files to PDF/A with Ghostscript 9.15.</p>
  
  <ol>
  <li><p>Is Ghostscript able to create PDF/A-3b conformant PDFs? There is no parameter which represents a PDF/A conformance level, so I assume there is no possibility. Or is there anything I have overlooked?</p></li>
  <li><p>I was following a blog post where a Windows batch file is used to convert from PDF to PDF/A (see <a href="http://www.mcbsys.com/techblog/2013/04/batch-convert-pdf-to-pdfa/" rel="nofollow">http://www.mcbsys.com/techblog/2013/04/batch-convert-pdf-to-pdfa/</a>). The <code>gs</code> invokation in the batch is:</p>
  
  <pre><code>"%gs_path%\gswin64c" ^
   -dPDFA ^
   -dNOOUTERSAVE ^
   -sProcessColorModel=DeviceRGB ^
   -sDEVICE=pdfwrite ^
   -o "GS_%file1%" ^
   -dPDFACompatibilityPolicy=1 ^
    "%currentdir%\PDFA_def.ps" ^
    %inputfilelist%
  </code></pre></li>
  </ol>
  
  <p>The <em><code>PDFA_def.ps</code></em> is an adjusted version of the official one:</p>
  
  <pre><code>%!
  % This prefix file for creating a PDF/A document is derived from
  % the sample included with Ghostscript 9.07, released under the
  % GNU Affero General Public License. 
  % Modified 4/15/2013 by MCB Systems.
  
  % Feel free to modify entries marked with "Customize".
  
  % This assumes an ICC profile to reside in the file (AdobeRGB1998.icc),
  % unless the user modifies the corresponding line below.
  
  % The color space described by the ICC profile must correspond to the
  % ProcessColorModel specified when using this prefix file (GRAY with
  % DeviceGray, RGB with DeviceRGB, and CMYK with DeviceCMYK).
  
  % Define entries in the document Info dictionary :
  
  /ICCProfile (... PATH TO ... AdobeRGB1998.icc)   % Customize.
  def
  
  [ /Title (Title)                  % Customize.
    /DOCINFO pdfmark
  
  % Define an ICC profile :
  
  [/_objdef {icc_PDFA} /type /stream /OBJ pdfmark
  [{icc_PDFA} &lt;&lt;/N systemdict /ProcessColorModel get /DeviceGray eq {1} {systemdict /ProcessColorModel get /DeviceRGB eq {3} {4} ifelse} ifelse &gt;&gt; /PUT pdfmark
  [{icc_PDFA} ICCProfile (r) file /PUT pdfmark
  
  % Define the output intent dictionary :
  
  [/_objdef {OutputIntent_PDFA} /type /dict /OBJ pdfmark
  [{OutputIntent_PDFA} &lt;&lt;
    /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 (AdobeRGB1998)      % Customize
  &gt;&gt; /PUT pdfmark
  [{Catalog} &lt;&lt;/OutputIntents [ {OutputIntent_PDFA} ]&gt;&gt; /PUT pdfmark
  </code></pre>
  
  <p>So, I use <em>AdobeRGB1998.icc</em> which is obviously useable for PDF files with RGB color space. Depending on the <code>-sProcessColorModel</code> value (DEVICERGB) a correct value is printed out.</p>
  
  <p>The conversion works for all files. But when I validate the created PDF file against PDF/A-1b, I get different results depending whether the input file has RGB color space or not (e.g. CMYK). So, when I have an input PDF file which uses CMYK color space, the file gets converted by the script, but the validator says something like this:</p>
  
  <pre><code>input.pdf", 1, 38, 0x03418614, "A device-specific color space (DeviceCMYK) without an appropriate output intent is used.", 1
  "output.pdf", 20, 0, 0x83410612, "The document does not conform to the requested standard.", 1
  </code></pre>
  
  <p>My question: Is there a way to get the conversion done for arbitrary files (i.e. independent of the used color space in the input file)? </p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>@KenS Thanks for your answer. I've updated my initial post to clarify what I want to achieve.</p>
  
  <p>To make it more explicit, I will use an example. There are two files: <code>input1.pdf</code> (seems to use RGB) and <code>input2.pdf</code> (seems to use CMYK). I want to convert both of them to PDF/A-1. Thanks to your hint, I've let go of the above mentioned batch script and instead tested the command directly in the command line. After reading <a href="http://git.ghostscript.com/?p=ghostpdl.git;a=blob_plain;f=gs/doc/Ps2pdf.htm;hb=HEAD#PDFA" rel="nofollow">Ps2pdf.htm#PDFA</a>, I have adjusted the (official) <em>PDFA_def.ps</em> so that <em>AdobeRGB1998.icc</em> is used. Then I invoked the following command on both input files (replaced <em>output1.pdf</em> by <em>output2.pdf</em> and <em>input1.pdf</em> by <em>input2.pdf</em> for the second file):</p>
  
  <pre><code>gswin64c.exe -dPDFA=1 -dBATCH -dNOPAUSE -dNOOUTERSAVE \
               -sColorConversionStrategy=/RGB \
               -sOutputICCProfile=AdobeRGB1998.icc -sDEVICE=pdfwrite \
               -sOutputFile=output1.pdf -dPDFACompatibilityPolicy=1 \
                "PATH/TO/OFFICIAL/PDFA_def.ps" input1.pdf
  </code></pre>
  
  <p>The conversion was done without any errors. The output1.pdf seems to be valid, but the output2.pdf is still invalid (tested with 3heights Validator):</p>
  
  <pre><code>"output2.pdf", 1, 40, 0x03418614, "A device-specific color space (DeviceCMYK) without an appropriate output intent is used.", 1
  "output2.pdf", 20, 0, 0x83410612, "The document does not conform to the requested standard.", 1
  </code></pre>
  
  <p>So when I understand your answer correctly, the above command should produce a pdf file which uses the RGB color space - independent of the color space of the input file. If the input file uses CMYK, than the colors have to be translated into RGB with the above command.</p>
  
  <p>When I interpret the first error message correctly, the used color space in the output2.pdf is still CMYK (although the command parameters like ColorConversionStrategy=/RGB). Since I used AdobeRGB1998.icc, the validation error appears.</p>
  
  <p>What am I missing in the above command?</p>
  
  <p>Going back to my original question (which is one step further): Instead of always converting to RGB (or CMYK), I wanted to somehow detect which color space is used in the input file and then dynamically switch to a RGB or CMYK icc file. Is it possible to achieve that?</p>