Simple Pdf Preview Extension for SilverStripe CMS
Create Jpg Preview Images of Pdf files on the fly.
Via Composer
{
"require": {
"ivoba/silverstripe-simple-pdf-preview": "~1.0"
}
}
- SilverStripe 4
- you will need the Imagick extension.
In your template just call $Pdf.getPdfPreviewImage
where $Pdf is your File Object, containing a pdf file.
You then have a normal Image object, on which you can apply all methods you usually can apply on an image in SilverStripe.
F.e.: $Pdf.getPdfPreviewImage.CroppedImage(60,60)
If you call this method on a non-pdf file, null will be returned.
You can override all Params in your config.yml.
SimplePdfPreviewImageExtension:
dependencies:
generator: %$SimplePdfPreviewExecGenerator
folderToSave: "assets/someOtherFolder/"
imagePrefix: "pdf-foobar"
Injector:
SimplePdfPreviewExecGenerator:
class: SimplePdfPreviewExecGenerator
You can create your own Generator class, simply implement SimplePdfPreviewGeneratorInterface
.
This could be the case, when we you dont want to use Imagick but ImageMagick directly via exec.
This extension is "simple" because it will just create a loose Image object.
Mapping happens over the filename. So its rather risky, but sufficient for most cases.
Somebody please make a better PDF extension, with a PDF File type, a PDF FileField and a preview image generation after upload. :)
The MIT License (MIT). Please see License File for more information.