Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to load the domPDF library in phalcon 3.2.3?

I am working on Phalcon 3.2 and I try to use the DomPDF library, someone who has implemented it to tell me how I add it?


hmm intresting, i am using mpdf, didnt know about this one.

Anyways, implementing "standalone" libraries has nothing to do with Phalcon, you have to implement them in your own way. Here are some code samples of my workers which are sending emails

$di->set('simpleView', function ($dir) use ($config) {

        $view = new \Phalcon\Mvc\View\Simple();
        $eventsManager = new EventsManager();

            '.phtml' => function ($view, $di) {

                $phtml = new \Phalcon\Mvc\View\Engine\Php($view, $di);

                return $phtml;
            '.volt'  => function ($view, $di) use ($config) {

                $volt = new  \Phalcon\Mvc\View\Engine\Volt($view, $di);
                    'compileAlways' => true,
                    'compiledPath'  => $config->voltCompileDir

                $compiler = $volt->getCompiler();
                $compiler->addFunction("money_format", "money_format");
                $compiler->addFunction("round", "round");
                $compiler->addFunction("hashIds", function ($resolvedArgs, $exprArgs) {

                    return $this->getShared("hashIds")->encode($resolvedArgs);

                return $volt;

        $eventsManager->attach("view:afterRender", function ($event, $view) {

            $search = [
                '/\>[^\S ]+/s',  // strip whitespaces after tags, except space
                '/[^\S ]+\</s',  // strip whitespaces before tags, except space
                '/(\s)+/s'       // shorten multiple whitespace sequences

            $replace = [

            $view->setContent((string)preg_replace($search, $replace, $view->getContent()));

        return $view;

    //in the controller 
    $html = $this->simpleView->render("somevoltfile.volt", ['my-data' => "somevar" ... ]);

    //create the pdf should be something like this
    $dompdf = new Dompdf\Dompdf();

    $output = $dompdf->output();
    file_put_contents('/var/www/mysite/filename.pdf', $output);

edited Nov '17

The easy way: download dompdf inside a dir like lib/vendor/dompdf and define your LIB_PATH. Then include this lines wherever you need:

    $dompdf = new \DOMPDF();  

                  // debug pdf  

you should wrap it inside a phalcon pdf class created ad hoc for generating pdf.