Just run a php file with:
phpinfo(); // nothing else in it.
Be part of JetBrains PHPverse 2026 on June 9 ā a free online event bringing PHP devs worldwide together.
What is the best way to detect PDF version with PHP? I know there are some external libraries that can be run from the command line but I only need to find out if I need to run ghostscript in the first place.
Thanks!
Hi @cronix and thank you all for your answers.
My problem was that I'm using FPDI to annotate pdf files that I receive via webhooks. The problem was that the free version of FPDI did not support pdf's in version higher than 1.4 and some of my files were in the higher versions.
It turns out it is not so easy to detect the version of PDF file with PHP, yes you can parse mime data and hope to find it there but it is a solution from 2011 and somewhat buggy as I could see.
Some other people suggested using the command line tools. Now, this is an acceptable and free solution but in my case, I would have to run one CLI tool to detect version then another CLI tool called ghostscript to downgrade PDF version to 1.4 and then run it via FPDI.
I mentioned that there is a paid version of FPDI, actually it is an additional package that you can purchase, that requires zero code updates, just pull it in from their private repo and magically support for higher versions will be there. Additional bonus will be also that all the logic and code needed will be still in your repo and will not be dependent on the configuration of your server.
I know that some people see paying for packages as a silly move but I have no problem with that. Paid 100e for it and it works seamlessly with original FPDI. Happy days.
Hope it helps someone!
Please or to participate in this conversation.