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

24 lines
528 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 = [];
collect($lines)
->map(fn(string $line) => explode(':', $line, 2))
->filter(fn(array $parts) => count($parts) === 2)
->each(fn(array $parts) => $data[trim($parts[0])] = trim($parts[1]));
return Metadata::fill($data);
}
}