How to convert PDF version 1.5 to version 1.4 in PHP

How to convert PDF version 1.5 to version 1.4 in PHP? Can someone point me in the right direction?

+10
source share
4 answers

I have a similar requirement, and I found that Ghostscript can change the version of PDF. The documentation is here: http://ghostscript.com/doc/current/Use.htm

However, I did not find anything specific about the dCompatibilityLevel parameter 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 
+11
source

You can easily convert PDF version 1.5 to 1.4. I am currently working in the same situation when I need to convert a PDF version. I noticed in my case that the PDF created from the dompdf library is version 1.3 and I use 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 file, not all).

so when my dompdf generates PDF version 1.3, I will convert it to version 1.4 because 1.4 is great for my Mozilla browser and indeed for all browsers.

You can convert the PDF version using 2 methods.

1) use ghostscript command line tool

 <?php exec('gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH -sOutputFile=new.pdf old.pdf') ?> 

2. using the PHP library specified in github. Download it from here.

I am currently working on this tool that encrypts a PDF file. It is almost ready and ready to use. Here

+3
source

I had the same problem for many years, without reinstalling any things, there is an online converter: https://docupub.com/pdfconvert/

+2
source

Here is a working full script, not perfect, but simple. The script reads all pdf from c: \ temp_in \, converts them and saves them as version 1.4 in the c: \ temp_done folder. There were problems with the paths to the ghost script, so the path is fully declared in shell_exec. Also added some debugging to the script by implementing "2> & 1". (Obviously, a ghost script requires installation.)

 <?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); } ?> 
0
source

Source: https://habr.com/ru/post/917984/


All Articles