We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

problem for to generate pdf in debian

Hello I have a little problem to generate pdf ... I'm using DOMPDF and HTML2PDF my basic example ... the example works in Windows but in Debian doesn't work

my steps were as follows

  1. phalcon create-project phalconpdf.
  2. require dompdf in composer.
  3. register Classes dompdf and html2pdf.
<?php

$loader = new \Phalcon\Loader();

/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs(
    array(
        $config->application->controllersDir,
        $config->application->modelsDir,
        $config->application->libraryDir,
    )
)
->registerClasses(
    array(
        "domPdf" => "/../../vendor/dompdf/dompdf/dompdf_config.inc.php",
        "html2Pdf" => "/../../vendor/html2pdf/html2pdf.class.php"
    )
)
->register();

// Use composer autoloader to load vendor classes
require_once __DIR__ . '/../../vendor/autoload.php';

in the IndexController i have

<?php

class IndexController extends ControllerBase
{

    public function dompdfAction()
    {
        $this->view->disable();
        $html = $this->view->getRender("index","dompdf");
        $dompdf = new domPdf;
        $dompdf->load_html($html);
        $dompdf->render();
        $dompdf->stream("exampledom.pdf");

    }

    public function html2pdfAction(){

        $this->view->disable();
        $content = $this->view->getRender("index","html2pdf");
        $html2pdf = new html2Pdf('P','A4','fr');
        $html2pdf->WriteHTML($content);
        $html2pdf->Output('exemplehtml.pdf');
    }

}

and my views are


// views/index/dompdf.volt
<h1>DOMPDF</h1>
<article>
Phalcon is an open source, full stack framework for PHP written as a C-extension, optimized for high performance. You don’t need to learn or use the C language, since the functionality is exposed as PHP classes ready for you to use. Phalcon also is loosely coupled, allowing you to use its objects as glue components based on the needs of your application.
</article>

// views/index/html2pdf.volt
<h1>HTML2PDF</h1>
<p>
Phalcon is an open source, full stack framework for PHP written as a C-extension, optimized for high performance. You don’t need to learn or use the C language, since the functionality is exposed as PHP classes ready for you to use. Phalcon also is loosely coupled, allowing you to use its objects as glue components based on the needs of your application.
</p>

what is problem?

When you say "it doesn't work", are you getting an error or an exception?



17.7k

no ... no errors but neither download the pdf

edited May '15

It could be you need to specify the content/type for PDF https://stackoverflow.com/questions/312230/proper-mime-media-type-for-pdf-files



17.7k

??????

$this->response->setHeader("Content-Type", "example/pdf");


34.6k
Accepted
answer

Yeah,

$this->response->setHeader("Content-Type", "application/pdf");

or

$response->setContentType('application/pdf');


17.7k

don't work =(



17.7k
edited May '15

i create a new controller "ReportController" and put the content-type and works .. thank youuuuu =)