How to convert PDF version 1.5 to version 1.4 in PHP ? Can anyone point me in the right direction ?
问题:
回答1:
I have a similar requirement, and found that Ghostscript can modify a PDF version. Documentation is here: http://ghostscript.com/doc/current/Use.htm
However, I didn't find anything specific about the dCompatibilityLevel option in the documentation. Rather, I found this article that demonstrated its use: http://rohieb.wordpress.com/2012/06/09/use-ghostscript-to-convert-pdf-files/
Here is the command:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH
-sOutputFile=new-pdf1.5.pdf original.pdf
回答2:
I had same problem for years, without reinstalling any stuff, there is an online converter: https://docupub.com/pdfconvert/
回答3:
you can easily convert PDF version 1.5 to 1.4 .
you can convert PDF version using 2 ways.
- use ghostscript command line tool
exec('gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH -sOutputFile=new.pdf old.pdf')
- using a PHP library given at github. Download it from here
I developed a PDF encryption tool which encrypt any version of pdf file. I used ghost-script to convert PDF version before passing PDF to fpdi pdf parser for encryption. it is almost done and ready to use . Here
回答4:
Here is a working complete script, not perfect but simple. Script reads all pdf's from c:\temp_in\ converts them and saves them as version 1.4 in folder c:\temp_done. Had some trouble with paths to the ghost script so path is declared fully in the shell_exec. Also added some debugging to the script by implementing "2>&1". (Obviously ghost script is installation is required.)
<?php
if ($handle = opendir("c:/temp_in/")) {
while (false !== ($file = readdir($handle))) {
if ('.' === $file) continue;
if ('..' === $file) continue;
$result = shell_exec('"C:\Program Files\gs\gs9.27\bin\gswin64c" -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH -sOutputFile="c:\temp_done\\'.$file.'" "c:\temp_in\\'.$file.'" 2>&1');
echo $result;
}
closedir($handle);
}
?>