pdfToText = $pdfToText; return $this; } /** * Gets the PdfToText driver. * * @return PdfTotext */ public function getPdfToText() { return $this->pdfToText; } public function read(MediaInterface $media) { $ret = []; $mimeType = $media->getFile()->getMimeType(); foreach ([ 'getWidth' => 'TfWidth', 'getHeight' => 'TfHeight', 'getChannels' => 'TfChannels', 'getColorDepth' => 'TfBits', 'getDuration' => 'TfDuration', ] as $method => $tag) { $classname = 'Alchemy\\Phrasea\\Metadata\\Tag\\'.$tag; if (method_exists($media, $method)) { $ret[] = new Metadata(new $classname(), new MonoValue(call_user_func([$media, $method]))); } } if ($mimeType == 'application/pdf' && null !== $this->pdfToText) { try { $text = $this->pdfToText->getText($media->getFile()->getRealPath()); if (trim($text)) { $ret[] = new Metadata(new PdfText(), new MonoValue($text)); } } catch (XPDFException $e) { } } $ret[] = new Metadata(new TfMimetype(), new MonoValue($mimeType)); $ret[] = new Metadata(new TfSize(), new MonoValue($media->getFile()->getSize())); $ret[] = new Metadata(new TfBasename(), new MonoValue(pathinfo($media->getFile()->getFileName(), PATHINFO_BASENAME))); $ret[] = new Metadata(new TfFilename(), new MonoValue(pathinfo($media->getFile()->getFileName(), PATHINFO_FILENAME))); $ret[] = new Metadata(new TfExtension(), new MonoValue(pathinfo($media->getFile()->getFileName(), PATHINFO_EXTENSION))); return $ret; } }