public function PdfPreviewGenerator::getPdfPreview in PDFPreview 2.0.x
Same name and namespace in other branches
- 8 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;
}
}