pdf-finder/src/IO/Shell/Pdfinfo.php

26 lines
510 B
PHP

<?php
namespace IO\Shell;
use PDF\Metadata;
class Pdfinfo
{
use ShellCommandExecutor;
public function getMetadata(string $filepath): Metadata
{
$lines = $this->shellExec('pdfinfo', '-isodates', $filepath);
$data = [];
foreach ($lines as $line) {
$parts = explode(':', $line, 2);
if (count($parts) === 2) {
$data[trim($parts[0])] = trim($parts[1]);
}
}
return (new Metadata)->fillWith($data);
}
}