Read the version of a PDF in PHP

The following is a very short code to read the version number of a PDF document using PHP. I needed this recently during a PDF processing app developed in PHP. As Adobe uses different compression methods in various versions, it becomes necessary to be able to identify the version of the PDF under work.

function pdfVersion($filename)
    $fp = @fopen($filename, 'rb');
    if (!$fp) {
        return 0;
    /* Reset file pointer to the start */
    fseek($fp, 0);
    /* Read 20 bytes from the start of the PDF */
    if (isset($match[0])) {
        return $match[0];
    } else {
        return 0;
$version = pdfVersion("example.pdf");

This site is a digital habitat of Sameer Borate, a freelance web developer working in PHP, MySQL and WordPress. I also provide web scraping services, website design and development and integration of various Open Source API's. Contact me at metapix[at] for any new project requirements and price quotes.

7 Responses


arne tarara

July 21st, 2011 at 9:57 am

Nice to know, but the call to fseek is overhead. The ‘r’ option sets the file pointer to the beginning anyway


Daniel Carrero

July 22nd, 2011 at 8:59 am

Excellent post!
I read in post ->
But they mention the function “pdf_get_value”
I prefer your function is independent of external libraries or modifications to php.
I will republish this post on my blog, if you give me permission for it.

Thanks a lot


Leer la version de un PDF con PHP | Blog de Daniel Carrero

July 22nd, 2011 at 9:30 am

[…] trata de una función php, creada por Sameer Borate que nos permite saber la versión de un archivo […]


July 22nd, 2011 at 7:53 pm

Daniel, you are free to publish the post on your blog.


Sameer Borate Blog: Lesen Sie die Version eines PDF in PHP | PHP Boutique

July 22nd, 2011 at 10:53 pm

[…] Borate hat einen schnellen Beitrag in seinem Blog heute mit etwas Code, mit dem Sie Lesen Sie die Version eines PDF-Dokuments programmatisch ohne Abhängigkeit von einem PDF-Erweiterung oder-Bibliothek installiert. Die […]


Programowanie w PHP » Blog Archive » Sameer Borate’s Blog: Read the version of a PDF in PHP

July 26th, 2011 at 5:42 am

[…] Borate has a quick post to his blog today with some code that lets you read the version of a PDF document programmatically without a dependency on a PDF extension or library being installed. The […]


Leonard Rosenthol

July 26th, 2011 at 12:15 pm

Actually, this code won’t work with many PDF files.

For over ten years now (since PDF 1.4), there has been a way for the version number in the header to be overwritten later on in the document, should newer content be added that increases the version.

The only way to determine the version of a PDF ACCURATELY is to parse the file according to the rules of the standard (ISO 32000-1:2008). That’s why using tools such as PDFlib and others are worthwhile.

Leonard Rosenthol
PDF Architect
Adobe Systems

Your thoughts

Sign up for fresh content in your email