Git Product home page Git Product logo

heyday-silverstripe-wkhtml's Introduction

Silverstripe Wkhtml - by Heyday

Build Status

This module provides a SilverStripe-centric wrapper for Snappy and wkhtml.

A SilverStripe 2.4 version is available in the 1.0 branch.

Requirements

Installation

$ composer require "heyday/silverstripe-wkhtml:~1.0.6"

How to use

Four things are required to generate a pdf or an image:

  • Knp\Snappy\GeneratorInterface The wrapper for wkhtmltopdf or wkhtmltoimage
  • Heyday\SilverStripe\WkHtml\Input\InputInterface to provide the html
  • Heyday\SilverStripe\WkHtml\Output\OutputInterface output the pdf or image in different ways
  • Heyday\SilverStripe\WkHtml\Generator to glue everything together

Available Inputs

  • Request (generates content from a request)
  • String (content is specified by a string)
  • Template (generates content from a SilverStripe template)
  • Url (generates content from a GET request to a Url)
  • Viewer (generates contetn from an SSViewer instance)

Available Outputs

  • Browser (outputs to the browser)
  • File (outputs to a file)
  • RandomFile (outputs to a random filename)
  • String (outputs to a string)

Available Generators

  • Pdf
  • Image

Examples

Full example (from a controller action)

use Heyday\SilverStripe\WkHtml;
$generator = new WkHtml\Generator(
    new \Knp\Snappy\Pdf('/pathto/wkhtmltopdf'),
    new WkHtml\Input\Url('/'),
    new WkHtml\Output\Browser('test.pdf', 'application/pdf')
);
return $generator->process();

Inputs

Request

new \Heyday\SilverStripe\WkHtml\Input\Request(
    new SS_HTTPRequest('GET', '/')
);
new \Heyday\SilverStripe\WkHtml\Input\Request(
    new SS_HTTPRequest('GET', '/'),
    new Session(
        array(
            'arg' => 'value'
        )
    )
);

String

new \Heyday\SilverStripe\WkHtml\Input\String(
    <<<HTML
<h1>Title</h1>
HTML
);

Template

new \Heyday\SilverStripe\WkHtml\Input\Template(
    'MyTemplate'
);
new \Heyday\SilverStripe\WkHtml\Input\Template(
    'MyTemplate',
    array(
        'Var' => 'Hello'
    )
);
new \Heyday\SilverStripe\WkHtml\Input\Template(
    'MyTemplate',
    new ArrayData(
        array(
            'Var' => 'Hello'
        )
    )
);
new \Heyday\SilverStripe\WkHtml\Input\Template(
    '$Var World',
    new ArrayData(
        array(
            'Var' => 'Hello'
        )
    ),
    true
);

Viewer

new \Heyday\SilverStripe\WkHtml\Input\Viewer(
    new SSViewer(
        array(
            'Template'
        )
    ),
    new ArrayData(
        array(
            'Var' => 'Hello'
        )
    )
);

Url

new \Heyday\SilverStripe\WkHtml\Input\Url('/');
new \Heyday\SilverStripe\WkHtml\Input\Url('http://google.co.nz/');

Outputs

Browser

new \Heyday\SilverStripe\WkHtml\Output\Browser('test.pdf', 'application/pdf'); // Force download
new \Heyday\SilverStripe\WkHtml\Output\Browser('test.pdf', 'application/pdf', true); // Embeds

File

new \Heyday\SilverStripe\WkHtml\Output\File(BASE_PATH . '/test.pdf');
new \Heyday\SilverStripe\WkHtml\Output\File(BASE_PATH . '/test.pdf', true); // Overwrite

Random File

new \Heyday\SilverStripe\WkHtml\Output\RandomFile(BASE_PATH);

String

new \Heyday\SilverStripe\WkHtml\Output\String();

##Unit Testing

$ composer install --dev
$ phpunit

License

This project is licensed under an MIT license

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.