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

24 lines
528 B
PHP
Raw Normal View History

2021-03-23 21:58:40 +01:00
<?php
namespace IO\Shell;
use PDF\Metadata;
class Pdfinfo
{
use ShellCommandExecutor;
public function getMetadata(string $filepath): Metadata
{
$lines = $this->shellExec('pdfinfo', '-isodates', $filepath);
$data = [];
2021-04-08 15:36:57 +02:00
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]));
2021-03-23 21:58:40 +01:00
2021-04-08 15:36:57 +02:00
return Metadata::fill($data);
2021-03-23 21:58:40 +01:00
}
}