mymotherland
mymotherland

Reputation: 8248

Render table is not fit inside pdf using DOMPDF in Zend?

I have the following piece of code taken from controller,

        ...
        $this->view->vCount = count($result);
        $this->view->Reportlist = $result;
          // create view object
        $html = new Zend_View();
        $html->setScriptPath(APPLICATION_PATH . '/layouts/scripts/');
        $html->assign('Reportlist', $this->view->Reportlist);
        $html->assign('vCount', $this->view->vCount);

        // render view
        $bodyText = $html->render('getreport.phtml');     
        //echo $bodyText; exit;
        //error_reporting(E_ALL);

        $dompdf = new DOMPDF();
        $dompdf->set_paper("a4","portrait");
        $dompdf->load_html($bodyText);

        $dompdf->set_base_path($_SERVER['DOCUMENT_ROOT']);
        $dompdf->render();
        $dompdf->stream($report_date.".pdf");
        .....

Above code generates pdf with my html content. But table is not inside pdf. HTML content render only half of the pdf. How can we make fit to PDF using DOMPDF ?

Upvotes: 0

Views: 8289

Answers (4)

Lightwaxx
Lightwaxx

Reputation: 765

It is POSSIBLE to fit a table in a page and you can use CSS for this (either inline or in head tag).

Ensure that you don't have styles table defining parameters like width="78" or something like that.

Upvotes: 0

MrGusan
MrGusan

Reputation: 1

All your content inside td elements should be in one line with opening and closing tags of td elements, adding new lines breaks rendering of table.

Change from:

<tr>
<td>
    Some of your content<br/>
    some other content
</td>

To:

<td>Some of your content<br/>some other content</td>

This should do the trick.

Upvotes: 0

Rashad
Rashad

Reputation: 1344

Unfortunately to fit the table inside PDF using DOMPDF is impossible. The DOMPDF team are still working on it and I can say that it is on top list between issues. You can follow this link to learn more about this bug...

DOMPDF issue

I would recommend you to use MPDF to fix your issue. I just now checked MPDF, it worked nice.

Upvotes: 1

John Doe
John Doe

Reputation: 67

DOMPDF has some issues with css and tables. Best practices are to avoid cell or rowspans and not using external css files. Also only a limited set of css rules are supported. Check out the full compatibility list: http://code.google.com/p/dompdf/wiki/CSSCompatibility

For fixing you're problem have you tried setting the width of the table:

<table width="90%">.. Your data here </table>

Edit: try putting the table in a <div></div>. This solved some generous errors

Upvotes: 3

Related Questions