Using ghostscript in a php script
<p>Using Laravel for a web app where I am using <a href="https://github.com/clegginabox/pdf-merger" rel="nofollow noreferrer">https://github.com/clegginabox/pdf-merger</a> to merge pdf files and ran into the following error when trying to merge two pdfs together where one was over version 1.4:</p>

<pre><code>Exception in pdf_parser.php line 133:

This document (C:\path-to-doc\file.pdf) probably uses a compression technique 
which is not supported by the free parser shipped with FPDI. 
(See https://www.setasign.com/fpdi-pdf-parser for more details)

in pdf_parser.php line 133
</code></pre>

<p>I followed the suggestion in the following answer to use ghostscript to convert any pdf over 1.4 to 1.4 so the merge will work.</p>

<p><a href="https://stackoverflow.com/questions/12154190/fpdf-error-this-document-testcopy-pdf-probably-uses-a-compression-technique-w#answer-29560767">FPDF error: This document (testcopy.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI</a></p>

<p>I've installed ghostscript successfully and added it to my path. For testing I have a sample pdf file which is version 1.5 called <code>test.pdf</code> and I run the following command from the windows terminal:</p>

<p><code>gswin64 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new-file.pdf test-file.pdf</code></p>

<p>and I get my <code>new-file.pdf</code> just fine as version 1.4.</p>

<p>Now I have the following php script which when ran from the web browser just loads continuously. If I let it run a bit sometimes a new file has been created but it's like 3kb in size and blank and also the original pdf file comes blank sometimes?!</p>

<pre><code>&lt;?php

shell_exec( "gswin64 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new-file.pdf test-file.pdf");

echo 'done';
</code></pre>

<p>Any ideas what I'm doing wrong?</p>