|
 |
|
ขอถามเรื่องการจัดตารางให้อยู่กึ่งกลางหน้ากระดาษ หรือให้ห่างจากขอบกระดาษด้านซ้ายของ pdf |
|
 |
|
|
 |
 |
|
ผมอยากให้ตารางอยู่กึ่งกลางหน้ากระดาษคัฟ
หรือให้ห่างจากขอบกระดาษด้านซ้ายก็ได้
ช่วยแนะนำด้วยครับ

Code (PHP)
<?php
require('pdf/fpdf.php');
class PDF extends FPDF
{
//Load data
function LoadData($file)
{
//Read file lines
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}
//Simple table
function BasicTable($header,$data)
{
//Header
$w=array(10,35,25,25,25);
//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
//Data
$num=1;
foreach ($data as $eachResult)
{
$this->Cell(10,6,$num++,1,0,'C');
$this->Cell(35,6,$eachResult["Date_Time"],1,0,'C');
$this->Cell(25,6,number_format($eachResult["Money_Old"],2),1,0,'R');
$this->Cell(25,6,number_format($eachResult["Deposit"],2),1,0,'R');
$this->Cell(25,6,number_format($eachResult["Balance"],2),1,0,'R');
$this->Ln();
}
}
//Colored table
function FancyTable($header,$data)
{
//Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//Header
$w=array(10,35,25,25,25);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
//Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
//Data
$fill=false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'C',$fill);
$this->Cell($w[0],6,$row[0],'LR',0,'C',$fill);
$this->Cell($w[0],6,number_format($row[0]),'LR',0,'R',$fill);
$this->Cell($w[0],6,number_format($row[0]),'LR',0,'R',$fill);
$this->Cell($w[0],6,number_format($row[0]),'LR',0,'R',$fill);
$this->Ln();
$fill=!$fill;
}
$this->Cell(array_sum($w),0,'','T');
}
}
$pdf=new PDF();
//Column titles
$header=array('ลำดับ','วันที่','เงินในบัญชี','ฝาก','คงเหลือ');
//Data loading
//*** Load MySQL Data ***//
include"connect.php";
$strSQL = "SELECT * FROM deposit WHERE Date2 BETWEEN '".$_GET['dateInput']."' and '".$_GET['dateInput2']."' order by ID ASC ";
mysql_query("SET NAMES TIS620");
$objQuery = mysql_query($strSQL);
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
$result = mysql_fetch_array($objQuery);
array_push($resultData,$result);
}
//************************//
define('FPDF_FONTPATH','font/');
include "connect.php";
$strSQL = "SELECT * FROM deposit WHERE ID_Account = '".$_SESSION['ID_Account']."' ";
mysql_query("SET NAMES TIS620");
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
$Name_Account = $objResult["Name_Account"];
//*** Table 1 ***//
$pdf->AddPage();
$pdf->AddFont('angsa','','angsa.php');
$pdf->SetFont('angsa','',14);
$pdf->Image('pdf/logo.jpg',95,8,20); //ขนาดรูปภาพ 90 = ห่างจากขอบกระดาษ 20 = ขนาดของรูป
$pdf->Ln(25);
$pdf->Cell(0,1,'รายงานการฝากเงินของ '.$Name_Account.' ',0,1,"C");
$pdf->Ln(5);
$pdf->Cell(0,1,'จากวันที่ '.$_GET['dateInput'].' ถึงวันที่ '.$_GET['dateInput2'].' ',0,1,"C");
$pdf->Ln(5);
$pdf->BasicTable($header,$resultData);
$pdf->Output("pdf/MyPDF/report-deposit-search.pdf","F");
echo "<a href=pdf/MyPDF/report-deposit-search.pdf target=_blank><img src=images/pdf-download-icon-lg.png width=40 border=0 /></a>";
?>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2014-02-28 22:11:23 |
By :
kunnawut |
View :
1624 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาไปศึกษาดูครับ
SetMargins(float left, float top [, float right]);
Code (PHP)
$pdf->SetMargins( 50,30,10 );
|
ประวัติการแก้ไข 2014-02-28 22:49:38
 |
 |
 |
 |
Date :
2014-02-28 22:47:22 |
By :
dekkuza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2014-03-01 10:22:21 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
         
|
 |
 |
 |
 |
Date :
2014-03-01 20:58:57 |
By :
dekkuza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|