public function PDFPreviewGenerator::getPDFPreview in PDFPreview 8
Same name and namespace in other branches
- 2.0.x src/PdfPreviewGenerator.php \Drupal\pdfpreview\PdfPreviewGenerator::getPdfPreview()
Gets the preview image if it exists, or creates it if it doesnt.
Parameters
\Drupal\file\Entity\File $file: The file to generate a preview for.
File
- src/
PDFPreviewGenerator.php, line 80
Class
- PDFPreviewGenerator
- Generates PDF Previews.
Namespace
Drupal\pdfpreviewCode
public function getPDFPreview(File $file) {
$destination_uri = $this
->getDestinationURI($file);
// Check if a preview already exists.
if (file_exists($destination_uri)) {
// Check if the existing preview is older than the file itself.
if (filemtime($file
->getFileUri()) <= filemtime($destination_uri)) {
// The existing preview can be used, nothing to do.
return $destination_uri;
}
else {
// Delete the existing but out-of-date preview.
$this
->deletePDFPreview($file);
}
}
if ($this
->createPDFPreview($file, $destination_uri)) {
return $destination_uri;
}
}