線上書籍

Home

[1012]PHP進階開發及TadTools工具應用

<?php include_once "header_admin.php"; include_once "../up_file.php"; require_once('../class/tcpdf/config/lang/zho.php'); require_once('../class/tcpdf/tcpdf.php'); $sn=empty($_REQUEST['sn'])?"0":intval($_REQUEST['sn']); //實體化PDF物件 $pdf = new TCPDF("L", PDF_UNIT, "A5", true, 'UTF-8', false); //$pdf->setPrintHeader(false); //不要頁首 //$pdf->setPrintFooter(false); //不要頁尾 $pdf->SetMargins(25, 25); $pdf->setHeaderMargin(5); $pdf->setFooterMargin(10); $pdf->setHeaderData('ck2.jpg', 40, '我的通訊錄', 'http://163.26.52.243/~tad0616/modules/contact', array(27,49,0), array(71,71,70)); $pdf->setFooterData(array(27,49,0), array(71,71,70)); $pdf->setHeaderFont(array('droidsansfallback','B','14')); $pdf->setFooterFont(array('droidsansfallback','I','16')); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //設定自動分頁 $pdf->setLanguageArray($l); //設定語言相關字串 $pdf->setFontSubsetting(true); //產生字型子集(有用到的字才放到文件中) $pdf->SetFont('droidsansfallback', '', 12, '', true); //設定字型 $sql = "select * from `".$xoopsDB->prefix("contact")."`"; $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); $all_content=""; $cate=get_contact_cate_all(); while($all=$xoopsDB->fetchArray($result)){ //以下會產生這些變數: $tel , $email , $name , $gsn , $sn , $birthday , $zip , $county , $city , $addr foreach($all as $k=>$v){ $$k=$v; } $pdf->AddPage(); //新增頁面 $pdf->setTextShadow(array('enabled'=>false, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));//文字陰影 $photo_file=get_pic_file('photo' , $sn , 1); $photo=empty($photo_file)?"":"<img src=\"{$photo_file}\">"; $html="<h1>「{$name}」通訊錄</h1> <table border=\"1\" cellpadding=\"4\"> <tr><th width=\"50\" align=\"center\" bgcolor=\"#CCFF66\">電話</th><td width=\"200\">{$tel}</td> <td width=\"200\" rowspan=\"4\">$photo</td></tr> <tr><th align=\"center\" bgcolor=\"#CCFF66\">信箱</th><td>{$email}</td></tr> <tr><th align=\"center\" bgcolor=\"#CCFF66\">生日</th><td>{$birthday}</td></tr> <tr><th align=\"center\" bgcolor=\"#CCFF66\">地址</th><td>{$zip} {$county}{$city}{$addr}</td></tr> </table>"; $pdf->writeHTML($html); include_once XOOPS_ROOT_PATH."/modules/tadtools/qrcode/qrcode.php"; $a = new QR("Email:{$email}"); file_put_contents(XOOPS_ROOT_PATH."/uploads/qrcode/{$sn}.gif",$a->image(2)); $pdf->Image(XOOPS_URL."/uploads/qrcode/{$sn}.gif", 170, 22 , 15, 15, 'gif'); } $pdf->Output('contact.pdf', 'I'); ?>