This module provides a SilverStripe-centric wrapper for Snappy and wkhtml.
A SilverStripe 2.4
version is available in the 1.0
branch.
- Composer
- Wkhtml binary either wkhtmltopdf or wkhtmltoimage
$ composer require "heyday/silverstripe-wkhtml:~1.0.6"
Four things are required to generate a pdf or an image:
Knp\Snappy\GeneratorInterface
The wrapper for wkhtmltopdf or wkhtmltoimageHeyday\SilverStripe\WkHtml\Input\InputInterface
to provide the htmlHeyday\SilverStripe\WkHtml\Output\OutputInterface
output the pdf or image in different waysHeyday\SilverStripe\WkHtml\Generator
to glue everything together
- Request (generates content from a request)
- TextString (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)
- Browser (outputs to the browser)
- File (outputs to a file)
- RandomFile (outputs to a random filename)
- TextString (outputs to a string)
- Image
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();
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'
)
)
);
new \Heyday\SilverStripe\WkHtml\Input\TextString(
<<<HTML
<h1>Title</h1>
HTML
);
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
);
new \Heyday\SilverStripe\WkHtml\Input\Viewer(
new SSViewer(
array(
'Template'
)
),
new ArrayData(
array(
'Var' => 'Hello'
)
)
);
new \Heyday\SilverStripe\WkHtml\Input\Url('/');
new \Heyday\SilverStripe\WkHtml\Input\Url('http://google.co.nz/');
new \Heyday\SilverStripe\WkHtml\Output\Browser('test.pdf', 'application/pdf'); // Force download
new \Heyday\SilverStripe\WkHtml\Output\Browser('test.pdf', 'application/pdf', true); // Embeds
new \Heyday\SilverStripe\WkHtml\Output\File(BASE_PATH . '/test.pdf');
new \Heyday\SilverStripe\WkHtml\Output\File(BASE_PATH . '/test.pdf', true); // Overwrite
new \Heyday\SilverStripe\WkHtml\Output\RandomFile(BASE_PATH);
new \Heyday\SilverStripe\WkHtml\Output\TextString();
##Unit Testing
$ composer install --dev
$ phpunit
This project is licensed under an MIT license