We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

PhalconPHP and DOMPDF

Good afternoon, trying to include this library for use in DOMPDF Phalcon views. I've checked the directory where the library, but can not find the class. Can anyone help me solve this? Thanks in Advance you very much. This did this / public / index.php

$ config = new Phalcon\Config\Adapter\Ini(__DIR__ .  '/app/config/config.ini'); 

/ / Register an autoloader 
     $ loader = new \ Phalcon \ Loader ();
     $ loader-> registerDirs (
         array (
             __DIR__. $ config-> application-> controllersDir,
             __DIR__. $ config-> application-> pluginsDir,
             __DIR__. $ config-> application-> libraryDir,
             __DIR__. $ config-> application-> modelsDir,
             __DIR__. $ config-> application-> libraryDir. "pdf /", / / ​​Add the folder for the PDF Dom
             __DIR__. $ config-> application-> libraryDir. "pdf / include /"
             __DIR__. $ config-> application-> libraryDir. "pdf / lib /"
         )
     ) -> register ();

please format source code with this guide https://forum.phalcon.io/help



40.8k
Accepted
answer

Hi, check if path for your library is ok and try https://localhost/pdf/render

class PdfController extends \Phalcon\Mvc\Controller
{
    public function renderAction()
    {
        $this->view->disable();

        require_once("app/library/pdf/dompdf_config.inc.php"); //you have to download this library and locate this file to bootstrap dompdf

        $html =
            '<html><body>'.
            '<p>test</p>'.
            '</body></html>';

        $dompdf = new DOMPDF();
        $dompdf->load_html($html);
        $dompdf->render();
        $dompdf->stream("sample.pdf");
    }
}
edited Jul '14

I am using phalcon 1.3.2 but it not work

class IndexController extends ControllerBase {

public function indexAction()
{
    $this->view->disable();
    require_once "app/library/dompdf/dompdf_config.inc.php";
    $html =
        '<html><body>'.
        '<p>test</p>'.
        '</body></html>';

    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
    $dompdf->stream("sample.pdf");
}

}

I add pdfDir in config/config.php like

return new \Phalcon\Config(array( 'database' => array( 'adapter' => 'Mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'dbname' => 'test', ), 'application' => array( 'controllersDir' => DIR . '/../../app/controllers/', 'modelsDir' => DIR . '/../../app/models/', 'viewsDir' => DIR . '/../../app/views/', 'pluginsDir' => DIR . '/../../app/plugins/', 'pdfDir' => DIR . '/../../app/library/', 'cacheDir' => DIR . '/../../app/cache/', 'baseUri' => '/blog/'

)

));

and in config/loader.php

$loader->registerDirs( array( $config->application->controllersDir, $config->application->modelsDir, $config->application->pdfDir

)

)->register();

and pdf not showing, after that i tried to remove this syntax (config/loader.php)

after I return again to the initial conditions but still error:

IndexController handler class cannot be loaded Why?