PHP code example of dmitrivereshchagin / yii-snappy

1. Go to this page and download the library: Download dmitrivereshchagin/yii-snappy 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/ */

    

dmitrivereshchagin / yii-snappy example snippets


'pdf' => array(
    'class' => 'dmitrivereshchagin\\yii\\snappy\\PdfComponent',
    'binary' => '/usr/local/bin/wkhtmltopdf',
    'options' => array('orientation' => 'landscape'),
    'tempdir' => basename(__DIR__).'/runtime/pdf',
),
'image' => array(
    'class' => 'dmitrivereshchagin\\yii\\snappy\\ImageComponent',
    'binary' => '/usr/local/bin/wkhtmltoimage',
    'tempdir' => basename(__DIR__).'/runtime/image',
),

Yii::app()->image->generate('http://example.com', '/path/to/image.jpg');

Yii::app()->pdf->generate('http://example.com', '/path/to/document.pdf');

Yii::app()->pdf->generate(
    array('http://example.com', 'http://example.org'),
    '/path/to/document.pdf'
);

Yii::app()->pdf->generateFromHtml(
    $this->render('view', array('name' => $value), $return = true),
    '/path/to/document.pdf'
);

$html = $this->render('view', array('name' => $value), $return = true);

Yii::app()->request->sendFile(
    'document.pdf',
    Yii::app()->pdf->getOutputFromHtml($html)
);

$url = Yii::app()->createAbsoluteUrl('controller/action');

Yii::app()->request->sendFile(
    'document.pdf',
    Yii::app()->pdf->getOutput($url)
);