In the end, this is how I did it.
I started by creating a new type of sketch in the configure method of my package controller as follows:
use Concrete\Core\File\Image\Thumbnail\Type\Type; ... public function configure($pkg) { ... $thumbnailType = new Type(); $thumbnailType->setName(tc('ThumbnailTypeName', 'PDF Thumbnails')); $thumbnailType->setHandle('pdfthumbnails'); $thumbnailType->setWidth(200); $thumbnailType->setHeight(200); $thumbnailType->save(); }
Then I created the mypackage/src/document_processing/pdfthumbnails.php with the following contents:
namespace Concrete\Package\Mypackage\Src\DocumentProcessing; use Core; use File; use Concrete\Core\File\Image\Thumbnail\Type\Type; class Pdfthumbnails { public function processPDFThumbnails($fv) { $fi = Core::make('helper/file'); $fvObj = $fv->getFileVersionObject(); $ext = $fi->getExtension($fvObj->getFilename()); $file = $fvObj->getFile(); if ($ext == 'pdf') { $type = Type::getByHandle('pdfthumbnails'); $basetype = $type->getBaseVersion(); $thumbpath = $basetype->getFilePath($fvObj); $fsl = $file->getFileStorageLocationObject()->getFileSystemObject(); $fre = $fvObj->getFileResource();
And then I connected to the on_file_version_add event in my package controller:
use Concrete\Package\Mypackage\Src\DocumentProcessing\Pdfthumbnails; ... public function on_start() { Events::addListener('on_file_version_add', array(new Pdfthumbnails(), 'processPDFThumbnails')); }
source share