duanpo1498 2013-04-24 12:59
浏览 76
已采纳

TCPDF有些变量不在输出文件中打印?

I am new to TCPDF PHP Library for pdf creation. I can be able to print first column of a table but could not able to print the rest. Here is my Code

<html>
<head>
<title>Admit Card</title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>

<style>
@media print {
  @page { margin: 0; }
  body { margin: 1.6cm; }
}
</style>
<script type="text/javascript" src="library/jquery-1.8.3.js" > </script> 
<script type="text/javascript">

    function PrintElem(elem)
    {
        Popup($(elem).html());
    }

    function Popup(data) 
    {
        var mywindow = window.open('', 'admit', 'width=800');
        mywindow.document.write('<html><head><title></title>');
        /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');

        mywindow.print();
        mywindow.close();

        return true;
    }

</script> </head> <body>
<div id="mydiv">
<?php
ob_start();
session_start();
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
//ob_start();
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'ISO-8859-1', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Dummy Dummy');
$pdf->SetTitle('Dummy Dummy');
$pdf->SetSubject('Dummy Dummy');
$pdf->SetKeywords('Dummy Dummy');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' CIT Kokrajhar', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

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

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// set font
$pdf->SetFont('dejavusans', '', 10);

// add a page
$pdf->AddPage();

$html='

 <table class="table" border="1"> <tr>
            <td>Sl. No.</td>
            <td>Name &amp; Father Name</td>
            <td>Nos.</td>
            <td>Roll Number</td>
            <td width="98">Photo</td>
            <td>Signature</td>
            <td>Remarks</td>
        </tr>
';
//$html = ob_start();
$pdf->writeHTML($html, true, false, true, false, '');

?>
<?php



//
        $username='root';
        $password = '';
        $conn = new PDO('mysql:host=localhost;dbname=somedbname',$username, $password);
if(isset($_GET['exam'])){
    try{
        $center=$_GET['center'];
        $exam=$_GET['exam'];


        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $strquery="SELECT * FROM dummytable_2013 WHERE `centre1`='".$center."' AND `examtype` LIKE '".$exam."%' ORDER BY RIGHT(`roll_number`, 3) ASC";
        $stmt=$conn->prepare($strquery);
        $stmt->execute();
        //$rs = $stmt -> get_result();
        $rows = $stmt -> fetchAll();
        $i=0;
        //print_r($rows);
        foreach($rows as $row){
            $i=$i+1;
            $form_number=$row['form_number'];
            $name=$row['name'];
            $roll=$row['roll_number'];
            $examtype=$row['examtype'];
            $sex=strtoupper($row['sex']);
            $dob = $row['dob'];
            $category = $row['category'];
            $countrycode = $row['nationality'];
            $email = $row['email'];
            $region = $row['region'];
            $examcenter1 =$row['centre1'];
            $examcenter2 = $row['centre2'];
            $examcenter3 = $row['centre3'];
            $fathersname = strtoupper($row['fathersname']);
            $mothersname = strtoupper($row['mothersname']);
            $paddress = strtoupper($row['paddress']);
            $caddress = strtoupper($row['caddress']);
            $examname1 = $row['exam1'];
            $year1 = $row['year1'];
            $grade1 = $row['grade1'];
            $percentage1 = $row['percentage1'];
            $examname2 = $row['exam2'];
            $year2 = $row['year2'];
            $grade2 = $row['grade2'];
            $percentage2 = $row['percentage2'];
            $examname3 = $row['exam3'];
            $year3 = $row['year3'];
            $grade3 = $row['grade3'];
            $percentage3 = $row['percentage3'];
            $ddnumber = $row['ddnumber'];
            $ddamount = $row['ddamount'];
            $dddate = $row['dddate'];
            $dddrawnat = $row['dddrawnat'];
            $ddbranch = $row['ddbranch'];
            $photo = $row['photoname'];
            $substr="substr";
            if($i%7==0){
                $pdf->lastPage();

                // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                // Print a table

                // add a page
                $pdf->AddPage();
                $html=<<<EOF

                <tr>
                        <td>{$substr($roll, -3)}</td>
                        <td>Candidates Name: 
                        Fathers Name: 
                        </td>
                        <td>{$substr($roll, -3)}</td>
                        <td></td>
                        <td><img src="{$photo}" border="1" width="95" height="105">
</td>
                        <td> &nbsp;{$i}</td>
                        <td>{$form_number}</td>
                </tr>
EOF;
//          $html = ob_start();
            $pdf->writeHTML($html, true, false, true, false, '');
            }
            else{
            $html=<<<EOF


        <tr>
            <td>{$substr($roll, -3)}</td>
            <td>Candidate&apos;s Name:
            Fathers Name: 
            </td>
            <td>{$substr($roll, -3)}</td>
            <td>{$roll}</td>
            <td><img src="{$photo}" border="1" width="95" height="105">
</td>
            <td> &nbsp;{$i}</td>
            <td>&nbsp;{$form_number}</td>
        </tr>

<?php
EOF;
//$html = ob_get_contents();
$pdf->writeHTML($html, true, false, true, false, '');
}
        }

                    //function to send email

    }
    catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }   

// reset pointer to the last page
$pdf->lastPage();

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('rep/'.$exam.'.pdf', 'F');
ob_clean();
?>
</table>
</div>
<center>
<input value="Print The Sheet" class="btn btn-large btn-success" onclick="PrintElem('#mydiv')" type="button">
</center>
</body>
</html>
<?php    
}
else{
    echo 'session not set';
}
?>

The result in the TCPDF output file is Only the content of first that is above the mysql connect. And the first column variable is printing. Result is below

TCPDF Example Dummy Dummy
by Nicola Asuni - Tecnick.com www.tcpdf.org






Sl. No.   Name & Father Name  Nos.    Roll Number   Photo     Signature       Remarks




001





002





003





004
  • 写回答

1条回答 默认 最新

  • douxuan4556 2013-04-24 18:15
    关注

    the problem i figured was due to proper table column height and width. After putting proper height and width to all of the colums i.e., in the td fields the rest field was able to get the values. Tcpdf is not printing values if there is not proper table properties. The problem is resolved now.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Open GL ES 的使用
  • ¥15 有人说Java多线程性质是非计算机科班硕士不懂的?
  • ¥15 我如果只想表示节点的结构信息,使用GCN方法不进行训练可以吗
  • ¥15 GPTs营销指令提示词和创建方案
  • ¥15 QT6将音频采样数据转PCM
  • ¥15 本地安装org.Hs.eg.dby一直这样的图片报错如何解决?
  • ¥15 下面三个文件分别是OFDM波形的数据,我的思路公式和我写的成像算法代码,有没有人能帮我改一改,如何解决?
  • ¥15 Ubuntu打开gazebo模型调不出来,如何解决?
  • ¥100 有chang请一位会arm和dsp的朋友解读一个工程
  • ¥50 求代做一个阿里云百炼的小实验