trekksoft/pdfversion

Reads the version of a PDF file.

2.0.0 2015-09-25 23:01 UTC

This package is auto-updated.

Last update: 2024-04-11 02:27:21 UTC


README

Build Status Code Coverage Scrutinizer Code Quality

Read the version of PDF files using PHP.

Installation

composer require "trekksoft/pdfversion":"~2.0"

Examples

Simple example

<?php
use Trekksoft\PdfVersion\File;
use Trekksoft\PdfVersion\VersionDiscovery\HeaderCommentDiscoverer;
use Trekksoft\PdfVersion\VersionDiscovery\UnknownVersionException;

$file = new File('path/to/file.pdf');

$discoverer = new HeaderCommentDiscoverer();

try {
    $version = $discoverer->getVersion($file);
    echo $version->toString();
} catch (UnknownVersionException $e) {
    echo $e->getMessage();
}

Trying multiple discoverers

$file = new File('path/to/file.pdf');

$discovererChain = new DiscovererChain([
    new HeaderCommentDiscoverer(),
    new YourOwnDiscoverer(),
    new SorryIhaventWrittenAnyOtherDiscoverers(),
]);

$version = $discovererChain->getVersion($file);

Using streams

<?php
$stream = new Stream($fileHandle);

$discoverer = new HeaderCommentDiscoverer();
$version = $discoverer->getVersion($stream);

License

MIT. See LICENSE file.