[982]PHP網站開發 進階應用技巧
<?php
require('fpdf/chinese-unicode.php');
include 'data.php';
// 產生一個 FPDF 物件
$pdf=new PDF_Unicode();
//設定UTF8字型
$pdf->AddUniCNShwFont('Uni');
// 目前還沒有任何頁面,使用 AddPage() 產生一個頁面
$pdf->AddPage("P","A4"); //AddPage([string 方向 ,[ mixed 格式]])
$pdf->SetAutoPageBreak(false);
$pdf->SetDisplayMode("fullpage","single");
$pdf->SetSubject("收據", true);
$pdf->SetCreator("ck2 system" , true);
$pdf->SetAuthor("tad", true);
$pdf->SetLeftMargin(20);
content($user,$data);
content($user,$data);
content($user,$data);
// 產 pdf 檔案應在瀏覽器上顯示出來
$pdf->Output();
//收據
function content($user="",$data=""){
global $pdf;
$pdf->Image("ck2_logo.png" , $pdf->GetX(),$pdf->GetY(),34, 10,"png");
// 設定字體格式
$pdf->SetFont('Uni','B',22);
$pdf->Cell(170 , 9 , "點兩下電腦工作室", 0 , 1 , "C");
//第二行
$pdf->SetFont('Uni','',14);
$pdf->Cell(65 , 8 , "單位名稱:{$user['company']}", 0 , 0);
$pdf->Cell(60 , 8 , "姓名:{$user['name']}", 0 , 0 );
$pdf->Cell(15 , 8 , "編號:", 0 , 0);
$pdf->SetTextColor(255,0,0); //前景色(紅)
$pdf->Cell(30 , 8 , time(), 0 , 1);
$pdf->SetTextColor(0,0,0); //前景色(黑)
//第三行
$pdf->SetFont('Uni','',12);
$pdf->Cell(75 , 8 , "項目", 1 , 0 ,"C");
$pdf->Cell(10 , 8 , "數量", 1 , 0 ,"C");
$pdf->Cell(25 , 8 , "單價", 1 , 0 ,"C");
$pdf->Cell(25 , 8 , "金額", 1 , 0 ,"C");
$pdf->SetFont('Uni','',9);
$pdf->Cell(35 , 4 , "實收金額", 1 , 2 ,"C");
$pdf->Cell(5 , 4 , "百", 1 , 0 ,"C");
$pdf->Cell(5 , 4 , "十", 1 , 0 ,"C");
$pdf->Cell(5 , 4 , "萬", 1 , 0 ,"C");
$pdf->Cell(5 , 4 , "千", 1 , 0 ,"C");
$pdf->Cell(5 , 4 , "百", 1 , 0 ,"C");
$pdf->Cell(5 , 4 , "十", 1 , 0 ,"C");
$pdf->Cell(5 , 4 , "元", 1 , 1 ,"C");
//項目內容
items(5,6,$data);
$pdf->SetY($pdf->GetY()+2);
$pdf->Text(122,$pdf->GetY()+4,"經手人:吳弘凱");
$pdf->Text(122,$pdf->GetY()+10,"日 期:".date("Y年m月d日"));
//注意事項
$text="一、本收據請妥為保管,以便日後查考。\n二、如欲查詢存款入帳詳情時,請檢附本收據及已填妥之查詢函交原存款局辦理。";
$pdf->SetFont('Uni','',9);
$pdf->MultiCell(100, 4, $text ,0);
$pdf->SetFont('Uni','',12);
$pdf->SetY($pdf->GetY()+10);
$pdf->Line(20,$pdf->GetY(),190,$pdf->GetY());
$pdf->SetY($pdf->GetY()+10);
}
//第四行(行數,高度)
function items($n=4,$h=7,$data=""){
global $pdf;
for($i=0 ; $i<$n ; $i++){
$sum=$data[$i][1] * $data[$i][2];
$pdf->Cell(75 , $h , $data[$i][0], 1 , 0 ,"C");
$pdf->Cell(10 , $h , $data[$i][1], 1 , 0 ,"C");
$pdf->Cell(25 , $h , $data[$i][2], 1 , 0 ,"C");
$pdf->Cell(25 , $h , $sum, 1 , 0 ,"C");
$sum_text=sprintf("%'-7s",$sum);
for($j=0;$j<7;$j++){
$w=substr($sum_text,$j,1);
$end=($j==6)?"1":"0";
$pdf->Cell(5 , $h , $w, 1 , $end ,"C");
}
}
//合計
$pdf->SetFont('Uni','',12);
$pdf->Cell(30 , $h , "合計", 1 , 0 ,"C");
$pdf->Cell(95 , $h , "元整", "B" , 0 ,"R");
$pdf->Cell(10 , $h , "", "B" , 0 ,"C");
$pdf->Cell(5 , $h , "", 1 , 0 ,"C");
$pdf->Cell(5 , $h , "", 1 , 0 ,"C");
$pdf->Cell(5 , $h , "", 1 , 0 ,"C");
$pdf->Cell(5 , $h , "", 1 , 0 ,"C");
$pdf->Cell(5 , $h , "", 1 , 0 ,"C");
$pdf->Cell(5 , $h , "", 1 , 0 ,"C");
$pdf->Cell(5 , $h , "", 1 , 1 ,"C");
}
?>