简体   繁体   English

在 Zend 中使用 DOMPDF 渲染表不适合 pdf?

[英]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.上面的代码用我的 html 内容生成 pdf。 But table is not inside pdf.但是表格不在pdf里面。 HTML content render only half of the pdf. HTML 内容仅呈现 pdf 的一半。 How can we make fit to PDF using DOMPDF ?我们如何使用 DOMPDF 适应 PDF ?

DOMPDF has some issues with css and tables. DOMPDF 在 css 和表格方面存在一些问题。 Best practices are to avoid cell or rowspans and not using external css files.最佳做法是避免使用单元格或行跨度,并且不使用外部 css 文件。 Also only a limited set of css rules are supported.此外,仅支持一组有限的 css 规则。 Check out the full compatibility list: http://code.google.com/p/dompdf/wiki/CSSCompatibility查看完整的兼容性列表: 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> .编辑:尝试将表格放在<div></div> This solved some generous errors这解决了一些慷慨的错误

Unfortunately to fit the table inside PDF using DOMPDF is impossible.不幸的是,使用 DOMPDF 将表格放入 PDF 中是不可能的。 The DOMPDF team are still working on it and I can say that it is on top list between issues. DOMPDF 团队仍在研究它,我可以说它在问题之间排在首位。 You can follow this link to learn more about this bug...您可以点击此链接以了解有关此错误的更多信息...

DOMPDF issue DOMPDF 问题

I would recommend you to use MPDF to fix your issue.我建议您使用 MPDF 来解决您的问题。 I just now checked MPDF, it worked nice.我刚刚检查了 MPDF,效果很好。

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. td 元素中的所有内容都应该与 td 元素的开始和结束标记在一行中,添加新行会中断表格的呈现。

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.这应该可以解决问题。

It is POSSIBLE to fit a table in a page and you can use CSS for this (either inline or in head tag).在页面中放置表格是可能的,您可以为此使用 CSS(内联或在 head 标签中)。

Ensure that you don't have styles table defining parameters like width="78" or something like that.确保您没有定义width="78" 之类的参数的样式表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM