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.

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?



9.0k

no ... no errors but neither download the pdf

edited May '15

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



9.0k

??????

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


33.6k
Accepted
answer

Yeah,

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

or

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


9.0k

don't work =(



9.0k
edited May '15

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