title: GhostScript - Merge pdfs from different directories
body: <p>I have to merge a number of pdf files, and am using the solution detailed <a href="https://stackoverflow.com/a/6288199/869177">here</a> to build a command to Ghostscript:</p>
  
  <pre><code>// $output_file_name = 'test_file_complete.pdf'
  // $original_file = 'test_file.pdf'
  // $append_files = array('../toappend/1.pdf', '../toappend/2.pdf', '../toappend/3.pdf', '../toappend/4.pdf')
  public function merge_documents($output_file_name, $original_file, $append_files) 
  {
      $cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$output_file_name ";
  
      $cmd .= $original_file . " ";
  
      foreach($append_files as $file) {
          $cmd .= $file . " ";
      }
  
      $result = shell_exec($cmd);
   }
  </code></pre>
  
  <p>The $cmd string I build is:</p>
  
  <pre><code>gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=test_file_complete.pdf test_file.pdf ../toappend/1.pdf ../toappend/2.pdf ../toappend/3.pdf ../toappend/4.pdf
  </code></pre>
  
  <p>Note that the first file to be merged is in the current directory, and the others are up a level in another directory. </p>
  
  <p>In the command line, when I navigate to the directory of the original file and run this, it works perfectly. However, in my function it fails with the message: </p>
  
  <blockquote>
    <p>(string) Error: /undefinedfilename in
    (TEMP_quote_2014_09_05_13_16_04.pdf) Operand stack:</p>
    
    <p>Execution stack:    %interp_exit   .runexec2   --nostringval--<br>
    --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push Dictionary stack:    --dict:1162/1684(ro)(G)--<br>
    --dict:0/20(G)--   --dict:77/200(L)-- Current allocation mode is local Last OS error: 2</p>
  </blockquote>
  
  <p>If I run that code using only the files in the "toappend" directory, it will merge those fine.</p>