1

我花了两天时间试图完成这项工作,我即将放弃。

我传递给 tcpdf::writeHTML() 的 HTML 是一个表格。(包含其他表格等...)

我的意思是字体超级难看,部分内容超出了页面,单元格内容从以前的单元格内容开始......即这是一个大混乱!

那么我做错了什么......因为它是,tcpdf 是完全无法使用的,它不可能是正确的!?

更新:我忘了提到 HTML 代码是有效的。(使用 W3.org 验证工具)

查看结果的截屏视频,包括预期的和生成的。

PHP代码:

<?php

require_once('./tcpdf/tcpdf.php');


class MYPDF extends TCPDF {

public function Header() {
    $image_file = './img/sfd.png';
    $this->Image($image_file, 10, 10, '', '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
    $this->SetFont('helvetica', 'B', 20);
    $this->Cell(0, 15, 'Feuille de Route', 0, false, 'C', 0, '', 0, false, 'M', 'M');
}

public function Footer() {
    $this->SetY(-15);
    $this->SetFont('helvetica', 'I', 8);
    $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}

}
function makePDF($clients ){
set_time_limit(0);

$pdf = new MYPDF("P", PDF_UNIT, "A3",true, 'UTF-8', false);

$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('St-Félicien Diesel');
$pdf->SetTitle('Feuille de route');
$pdf->SetSubject('Bilan de travail');
$pdf->SetKeywords('sfd');
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

$pdf->SetFont('dejavusans', '', 10);
$pdf->AddPage();
unset($client);
$client = str_replace("'", "\"", $clients[0]);

$pdf->writeHTML($client, true, false, true, false, '');

$pdf->Output('FeuilleRoute.pdf', 'i'); // show pdf

return true;
}

这是在 writeHTML() 中推送的确切 HTML:

<table width="100%" cellpadding="0" cellspacing="0">
<tr>
    <td><table width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <th colspan="8" scope="col"><table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td align="left" nowrap white-space="nowrap">Feuille de route No:</td>
                            <td width="100%" align="left">1</td>
                            <td width="140" align="right" nowrap white-space="nowrap">Client:</td>
                            <td align="left" nowrap white-space="nowrap">Krishna Motors</td>
                        </tr>
                        <tr>
                            <td width="100%" colspan="2"></td>
                            <td width="140" align="right" nowrap white-space="nowrap">Employé:</td>
                            <td align="left" nowrap white-space="nowrap">gilbert Rauzon</td>
                        </tr>
                        <tr>
                            <td width="100%" colspan="2"></td>
                            <td width="140" align="right" nowrap white-space="nowrap">Date:</td>
                            <td align="left" nowrap white-space="nowrap">2013-07-29</td>
                        </tr>
                        <tr>
                            <td width="100%" colspan="2"><table width="100%" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <th nowrap white-space="nowrap" scope="row">Note globale:</th>
                                        <td width="100%" align="left">Commentaire pour cette journée du 29 Juillet 2013.</td>
                                    </tr>
                                </table></td>
                            <td width="140" align="right" nowrap white-space="nowrap">Total des heures:</td>
                            <td align="left" nowrap white-space="nowrap">7hrs</td>
                        </tr>
                        <tr>
                            <td colspan="4" height="60" align="center" valign="middle">Détail</td>
                        </tr>
                    </table></th>
            </tr>
        </table></td>
</tr>
<tr>
    <td><table width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td width="100" scope="col"></td>
                <td colspan="6" height="20px" scope="col"></td>
                <td width="70" scope="col"></td>
            </tr>
            <tr>
                <th width="100" bgcolor="#999999" scope="col"></th>
                <th colspan="6" bgcolor="#999999" scope="col">Description</th>
                <th width="70" bgcolor="#999999" scope="col">Facturable</th>
            </tr>
            <tr>
                <td rowspan="2" width="100"><table width="120" cellpadding="0" cellspacing="0">
                        <tr>
                            <th bgcolor="#CCCCCC" align="right" scope="row">De:</th>
                            <td width="100%">07:00:00</td>
                        </tr>
                        <tr>
                            <th bgcolor="#CCCCCC" align="right" scope="row">À:</th>
                            <td width="100%">08:30:00</td>
                        </tr>
                    </table></td>
                <td colspan="6">Réparation diverse</td>
                <td rowspan="2" width="70" align="center">non</td>
            </tr>
            <tr>
                <th width="100" align="right">Departement:</th>
                <td align="left">KM Dep 82</td>
                <th width="40" align="right">Site:</th>
                <td align="left">KM Site 42</td>
                <th width="50" align="right">Unité:</th>
                <td align="left">KM-UNIT42</td>
            </tr>
            <tr>
                <td width="100" scope="col"></td>
                <td colspan="6" height="20px" scope="col"></td>
                <td width="70" scope="col"></td>
            </tr>
            <tr>
                <th width="100" bgcolor="#999999" scope="col"></th>
                <th colspan="6" bgcolor="#999999" scope="col">Description</th>
                <th width="70" bgcolor="#999999" scope="col">Facturable</th>
            </tr>
            <tr>
                <td rowspan="2" width="100"><table width="120" cellpadding="0" cellspacing="0">
                        <tr>
                            <th bgcolor="#CCCCCC" align="right" scope="row">De:</th>
                            <td width="100%">09:00:00</td>
                        </tr>
                        <tr>
                            <th bgcolor="#CCCCCC" align="right" scope="row">À:</th>
                            <td width="100%">12:00:00</td>
                        </tr>
                    </table></td>
                <td colspan="6">Job sur camion</td>
                <td rowspan="2" width="70" align="center">non</td>
            </tr>
            <tr>
                <th width="100" align="right">Departement:</th>
                <td align="left">KM Dep 52</td>
                <th width="40" align="right">Site:</th>
                <td align="left">KM Site 32</td>
                <th width="50" align="right">Unité:</th>
                <td align="left">KM-UNIT32</td>
            </tr>
            <tr>
                <th colspan="8" align="left" bgcolor="#CCCCCC">Pièces</th>
            </tr>
            <tr>
                <td colspan="8"><table width="80%" align="right" cellpadding="0" cellspacing="0">
                        <tr>
                            <th width="130" bgcolor="#CCCCCC" scope="col">Code</th>
                            <th bgcolor="#CCCCCC" align="left" scope="col">Note</th>
                            <th width="30" bgcolor="#CCCCCC" scope="col">Qty</th>
                            <th width="110" bgcolor="#CCCCCC" scope="col">Prix unitaire</th>
                        </tr>
                        <tr>
                            <td width="130">6667352</td>
                            <td>ABLAadsg asdfas dfsa</td>
                            <td width="30" align="center">4</td>
                            <td width="70" align="center">15 $</td>
                        </tr>
                    </table></td>
            </tr>
        </table></td>
</tr>

谢谢你的帮助 !

4

0 回答 0