PHP code example of mikehaertl / pdfable

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

    

mikehaertl / pdfable example snippets



    'modules'=>array(
        'pdfable'=>array(
            'class'=>'ext.pdfable.pdfable.PdfableModule',
            // Optional: Set path to wkthmltopdf binary
            //'bin' => '/usr/bin/wkhtmltopdf',
        ),


class MyController extends Controller
{
    public function behaviors()
    {
        return array(
            'pdfable'=>array(
                'class' => 'ext.pdfable.Pdfable',
            ),
        );
    }

    public function actionPdfDemo()
    {
        // Render this view as PDF and display inline in the browser:
        $this->renderPdf('pdfDemo');
    }


    public function actionInvoice($id)
    {
        $invoice=Invoice::model()->findByPk($id);

        $this->renderPdf('invoice',array(
            'invoice' => $invoice,
        ), array(), 'invoice_'.$invoice->id.'.pdf');
    }


    public function actionPortfolio($id)
    {
        $portfolio = Portfolio::model()->findByPk($id);

        $pdf = $this->createPdf();
        $pdf->renderPage('intro');
        $pdf->renderPage('portfolio',array(
            'portfolio' => $portfolio,
        ));
        $pdf->send('portfolio_'.$id.'.pdf');
    }

    public function actionIndex($filename)
    {
        $pdf = new PdfFile;

        // We have to set some paths ...
        $pdf->baseViewPath  = Yii::getPathOfAlias('ext.pdfable.pdfable.views');
        $pdf->layoutPath    = Yii::getPathOfAlias('ext.pdfable.pdfable.views.layouts');
        $pdf->viewPath      = Yii::getPathOfAlias('ext.pdfable.pdfable.views.demo');

        // ... and supply our custom CSS file
        $pdf->setOptions(array(
            'user-style-sheet'  => Yii::getPathOfAlias('ext.pdfable.pdfable.assets.css.pdf').'.css',
        ));

        $pdf->renderPage('invoice');
        $pdf->renderPage('page1');
        $pdf->renderPage('page2');

        $pdf->saveAs($filename);
    }


    'commandMap' => array(
        'demopdf' => array(
            'class' => 'ext.pdfable.pdfable.commands.DemopdfCommand',
        ),
    ),


   public function behaviors()
   {
       return array(
           'pdfable' => array(
               'class' => 'ext.pdfable.Pdfable',

               // Global PDF options (see wkhtmltopdf -H for details)
               'pdfOptions' => array(
                   'bin'   => '/usr/bin/wkhtmltopdf',  // path to executable (default)
                   'dpi'   => 600,
               ),

               // Default PDF page options (see wkhtmltopdf -H for details)
               'pdfPageOptions' => array(
                   'page-size'         => 'A5',

                   // You probably always need this, because CSS files from <link>
                   // tags in your document are ignored
                   'user-style-sheet'  => Yii::getPathOfAlias('webroot').'/css/pdf.css',
               ),

               // Use other tmp directory instead of Yii::app()->runtimePath
               'tmpAlias' => 'application.var.tmp',
           ),
       );
   }


   public function behaviors()
   {
       return array(
           'pdfable' => array(
               'class' => 'ext.pdfable.Pdfable',

               'defaultPdfOptions' => array(
                   ...
                   // default PDF options here
                   // could also be an empty array to disable all defaults
                   ...
               ),

               'defaultPdfPageOptions' => array(
                   ...
                   // default PDF page options here
                   // could also be an empty array to disable all defaults
                   ...
               ),
           ),
       );
   }