pdfghostscriptpostscriptpdfa

Pass argument from GhostScript CLI to PostScript


I'm using Ghostscript to convert PDF to PDF/A files, which works fine. I want to use the -dSAFER option, which forces me to use absolute path name for the ICCProfile in the file PDFA_def.ps:

% 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 (/var/www/myproject/gs/sRGB2014.icc) % Customise
def

[/_objdef {icc_PDFA} /type /stream /OBJ pdfmark

Using the following command, I can convert a PDF using GhostScript:

gs --permit-file-read=/var/www/myproject/gs/ \
    -dPDFA=3 \
    -dBATCH \
    -dNOPAUSE \
    -dSAFER \
    -sColorConversionStrategy=RGB \
    -sDEVICE=pdfwrite \
    -sOutputFile=output.pdf \
    /var/www/myproject/gs/PDFA_def.ps \
    input.pdf

Because this project is rolled out into a different folder on production, I'm looking for a way to make path names configurable. Because of -dSAFER we have to stay with absolut path names, I think. Just to mention, I'm a PHP developer, but I have no clue of PostScript.

Is there a way to pass the path /var/www/myproject/gs/ into the PostScript file PDFA_def.ps (this would be sufficient for me).


Solution

  • With the -sname=string command line option you can define a name in systemdict with a given string as value, and use that in the PostScript code. For example, if you call gs with

    -stheICCProfilePath=/var/www/myproject/gs/sRGB2014.icc
    

    then you can use that name in PDFA_def.ps with

    % Define an ICC profile :
    /ICCProfile theICCProfilePath def