问题
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:
you can easily convert PDF version 1.5 to 1.4 . At present i am working at the same situation where i need to convert the pdf version. i noticed in my case that PDF generated from a "dompdf" library is version 1.3 and i am using the latest mozilla firefox but still mozilla shows a black screen when i try to read my PDF . (black screen on any page of my multi-page PDF , not all).
so when my dompdf generates the PDF version 1.3 then i will convert it to version 1.4 because 1.4 is fine with my mozilla firefox and indeed all browsers.
you can convert PDF version using 2 ways.
1) use ghostscript command line tool
<?php
exec('gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH
-sOutputFile=new.pdf old.pdf')
?>
2. using a PHP library given at github. Download it from here
I am working on this tool at present which encrypt a pdf file. it is almost done and ready to use . Here
回答3:
I had same problem for years, without reinstalling any stuff, there is an online converter: https://docupub.com/pdfconvert/
回答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);
}
?>
来源:https://stackoverflow.com/questions/11017665/how-to-convert-pdf-version-1-5-to-version-1-4-in-php