ivoba/silverstripe-simple-pdf-preview

Simple Pdf Preview Extension for SilverStripe CMS

Installs: 785

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 2

Forks: 5

Open Issues: 0

Type:silverstripe-vendormodule

2.4.0 2024-10-11 11:08 UTC

This package is auto-updated.

Last update: 2024-11-11 11:31:15 UTC


README

Simple Pdf Preview Extension for SilverStripe CMS

Total Downloads

Create Jpg Preview Images of Pdf files on the fly.

Install

Via Composer

{
    "require": {
        "ivoba/silverstripe-simple-pdf-preview": "~2.0"
    }
}

Requirements

  • SilverStripe 4 or 5
  • you will need the Imagick extension.

For SilverStripe 3 use v1.

Usage

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.Fill(60,60)

If you call this method on a non-pdf file, null will be returned.

Config

You can override all Params in your config.yml.

Ivoba\SilverStripe\SimplePdfPreview\SimplePdfPreviewImageExtension:
  dependencies:
    generator: %$Ivoba\SilverStripe\SimplePdfPreview\SimplePdfPreviewImagickGenerator
    folderToSave: "assets/someOtherFolder/"
    imagePrefix: "pdf-foobar"

Injector:
  Ivoba\SilverStripe\SimplePdfPreview\SimplePdfPreviewImagickGenerator:
    class: Ivoba\SilverStripe\SimplePdfPreview\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.

Tests

To run tests for bundle standalone:

start the docker container:

docker-compose run php bash

inside the container run:

SS_DATABASE_NAME=ss SS_DATABASE_PASSWORD=ss SS_DATABASE_SERVER=db SS_DATABASE_USERNAME=ss vendor/bin/phpunit

Disclaimer

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. :)

License

The MIT License (MIT). Please see License File for more information.