Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aurawindsurfing's avatar

Detect PDF version with PHP

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!

0 likes
9 replies
jlrdw's avatar

Just run a php file with:

phpinfo();   // nothing else in it.
jlrdw's avatar

Ah go to symfony http foundation docs, but you need to find the api, then github code.

They have code in there that figures th php version. Sorry don't have link right off hand, will try to find again.

Here also https://www.php.net/manual/en/function.phpversion.php

I.e.,

quote

$ver = (float)phpversion();
if ($ver > 7.0) {
    //do something for php7.1 and above.
} elseif ($ver === 7.0) {
    //do something for php7.0
} else {
    //do something for php5.6 or lower.
}

unquote

jlrdw's avatar

@aurawindsurfing dang, I didn't realize my glasses had got so dirty.

What are you needing, like which and if someone has adobe pdf installed? Adobe has articles on this.

When you say pdf, what and who.

So many pdf extensions these days. I once used bullzip pdf.

But just generate one with js. I don't recall the name, but my online pharmacy (express scripts) uses one to generate pdf forms to print out.

aurawindsurfing's avatar

Hi @jlrdw

When I mean PDF I mean FPDI inside my laravel app processing / annotating PDF files I receive via webhook.

I need a way to check version of pdf file I’m receiving and if I want to apply a ghostscript and downgrade version of pdf to 1.4 since FPDI works only with up to 1.4

Thanks!

aurawindsurfing's avatar
Level 50

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!

2 likes

Please or to participate in this conversation.