Giter VIP home page Giter VIP logo

silverstripe-simple-pdf-preview's Introduction

silverstripe-simple-pdf-preview

Simple Pdf Preview Extension for SilverStripe CMS

Build Status 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
  • 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.

silverstripe-simple-pdf-preview's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.