带有表格pdf的Dompdf包含错误



我作为供应商在cakehp1.3应用程序中使用dompdf 0.6.0 beta 3。我的服务器的php版本是5.2。我作为附件生成的pdf包含用html助手生成的表,css在标题中声明。

我有一个非常奇怪的问题。通常生成的pdf没有问题,但在生成的pdf中,约有10%的文件包含错误,并且仅部分呈现。没有致命的错误,但不知何故pdf的生成是不对的。更奇怪的是,它与php代码在Session变量中获取的数据完全相同。因此,生成相同的数据有时没有任何问题(在90%的情况下),有时也会出现问题。

如果你有问题的线索,谢谢你。

这是生成pdf的代码。(Journal是我创建的助手,函数Journal::journalCheck输出一个表)

$html = 
'<html xmlns="http://www.w3.org/1999/xhtml">'.
    '<head>'.
        $this->Html->charset().
        '<style>
            ul{
                margin: 0px;
            }
            .enonces p{
                margin:0px;
            }
            table{
                border-collapse: collapse;
                width:100%;
                margin-bottom: 25px;
            }    
            table.legende{
                width:25%;
            }
            td{
                border: 1px solid black;
            }
            th{
                border: 1px solid black;
                background-color: #96ed88;
            }
            .noEcriture{
                width:5%;
            }
            .nomCompte{
                width:15%;
            }
            .montantCompte{
                width: 10%;
                text-align: right;
            }
            .libelle{
                width: 45%;
                min-width: 65px;
            }
            .faux{
                color: red;
                text-decoration:line-through;
            }
            .ecriture_fausse{
                background-color: pink;
            }
            td.correction_cell{
                background-color: #daafe7;
            }
            .consigne{
                font-style:italic;
            }
            .enonces{
                border: 1px solid black;
                margin-bottom: 20px;
            }
        </style>'.
    '</head>'.
    '<body>'.
        '<h1>'.
            $exercice[0]['Exercice']['nom'].
        '</h1>'.
        '<h3>'.
            'Exercice réalisé par '.$session->read('eleve.Exercice.prenom').'                            '.$session->read('eleve.Exercice.nom_famille').
            ' - version '.$session->read('exercice.'.$this->params['pass'][0].'version').
            ' - '.date('d/m/Y').
        '</h3>'.
        '<p class="consigne">'.
            $this->Journal->showConsigne($exercice[0]['Exercice']['consigne'],$raw = true).
        '</p>'.
        '<div class="enonces">'.
            $this->Journal->viewEnonce($enonces).
        '</div>'.
        $this->Journal->journalCheck($datas,$correct_datas,$ecriture_ids,$compte_ids,array('pdf'=>true)).
        '<p>'.
            'Légende:'.
        '</p>'. 
        '<table class="legende">'.
            $this->Html->tableCells(array(array('écriture juste'),
                                    array(array('écriture fausse',array('class'=>'ecriture_fausse'))),
                                    array(array('corrigé',array('class'=>'correction_cell'))))
                                    ).
        '</table>'.       
        '<p>'.
            'Source: <a href="'.$_SERVER['HTTP_HOST']."/".basename(ROOT)."/"."exercices/complete/".$this->params['pass'][0].'">'.
            $_SERVER['HTTP_HOST']."/".basename(ROOT)."/"."exercices/complete/".$this->params['pass'][0].'</a>'.             
        '</p>'.
    '</body>'.
'</html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("Journalizer_".$exercice[0]['Exercice']['nom']."_".$session->read('eleve.Exercice.nom_famille')."_".$session->read('eleve.Exercice.prenom')."_v".$session->read('exercice.'.$this->params['pass'][0].'version').".pdf", array("Attachment" => 1));

我不久前也遇到了同样的问题。问题是,当pdf太大时,dompdf会抛出错误。我现在找不到解决这个问题的方法,因为我再也没有访问代码的权限了。

尝试检查apache错误日志文件。如果你发现这个错误,那么你可以使用错误消息在谷歌上搜索答案。

需要一些简单的源代码单行编辑来修复此问题。

最新更新