PHP code example of heyday / silverstripe-wkhtml

1. Go to this page and download the library: Download heyday/silverstripe-wkhtml library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

heyday / silverstripe-wkhtml example snippets


use Heyday\SilverStripe\WkHtml;
use SilverStripe\Core\Injector\Injector;

$generator = WkHtml\Generator::create(
    // Use Injector->get(Pdf::class) if you don't need to modify options
    // Use Injector->create() to create a transient service for modifications (e.g. setOption)
    // Using Injector->get() and making changes will cause changes to be made for all uses of get(Pdf::class) for the entire request
    Injector::inst()->create(\Knp\Snappy\Pdf::class),
    WkHtml\Input\Url::create('/'),
    WkHtml\Output\Browser::create('test.pdf', 'application/pdf')
);
return $generator->process();

\Heyday\SilverStripe\WkHtml\Input\Request::create(
    // Controller::curr()->getRequest() is also an option
    Injector::inst()->get(\SilverStripe\Control\HTTPRequest::class)
);

\Heyday\SilverStripe\WkHtml\Input\Request::create(
    Injector::inst()->get(\SilverStripe\Control\HTTPRequest::class),
    new Session([
        'arg' => 'value',
    ])
);

$html = <<<HTML
<h1>Title</h1>
HTML;
\Heyday\SilverStripe\WkHtml\Input\TextString::create($html);

\Heyday\SilverStripe\WkHtml\Input\Template::create('MyTemplate');

\Heyday\SilverStripe\WkHtml\Input\Template::create(
    'MyTemplate',
    [
        'Var' => 'Hello',
    ]
);

\Heyday\SilverStripe\WkHtml\Input\Template::create(
    'MyTemplate',
    ArrayData::create([
        'Var' => 'Hello',
    ])
);

\Heyday\SilverStripe\WkHtml\Input\Template::create(
    '$Var World',
    ArrayData::create([
        'Var' => 'Hello',
    ]),
    true
);

\Heyday\SilverStripe\WkHtml\Input\Viewer::create(
    SSViewer::create([
        'Template',
    ]),
    ArrayData::create([
        'Var' => 'Hello',
    ])
);

\Heyday\SilverStripe\WkHtml\Input\Url::create('/');

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

\Heyday\SilverStripe\WkHtml\Output\Browser::create('test.pdf', 'application/pdf'); // Force download

\Heyday\SilverStripe\WkHtml\Output\Browser::create('test.pdf', 'application/pdf', true); // Embeds

\Heyday\SilverStripe\WkHtml\Output\File::create(BASE_PATH . '/test.pdf');

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

\Heyday\SilverStripe\WkHtml\Output\RandomFile::create(BASE_PATH);

\Heyday\SilverStripe\WkHtml\Output\TextString::create();