Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ขอความช่วยเหลือใน FPDF ให้แสดง Header แบบนี้ต้องเพิ่มยังไงครับ



 

ขอความช่วยเหลือใน FPDF ให้แสดง Header แบบนี้ต้องเพิ่มยังไงครับ

 



Topic : 120707



โพสกระทู้ ( 316 )
บทความ ( 0 )



สถานะออฟไลน์




ขอสอบถามครับ
ใน FPDF จะให้แสดงหัวตารางแบบนี้ต้องเพิ่มยังไงครับ ตามรูป
aa1

ตอนนี้ที่ทำออกมามันแสดงแบบนี้ครับ
aa2

Code
Code (PHP)
<html>
<head>
<title>test pdf</title>

</head>
<body>

<?php
define('FPDF_FONTPATH','font/');
require('pdf/fpdf.php');




class PDF extends FPDF
{
	
function Footer()
{
	
	$this->AddFont('angsa','','angsa.php');
	$this->AddFont('angsa','B','angsab.php');
	//$pdf->SetFont('angsa','',10);
//	$pdf->SetFont('angsa','B',12);
	
	$this->SetY(-15);
	$this->SetFont('angsa','B',8);
	$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
	
}

	
//Load data
function LoadData($file)
{
	//Read file lines
	$lines=file($file);
	$data=array();
	foreach($lines as $line)
		$data[]=explode(';',chop($line));
	return $data;
}


//Better table
function ImprovedTable($header,$data)
{
	//Column widths
	$w=array(46,18,18,18,18,18,18,18,20);
	//Header
	for($i=0;$i<count($header);$i++)
		$this->Cell($w[$i],7,$header[$i],1,0,'C');
	$this->Ln();
	//Data

	foreach ($data as $eachResult) 
	{
		
		
		$this->Cell(46,6,iconv( 'UTF-8','TIS-620',$eachResult["ItemCode"]),1);
		$this->Cell(18,6,iconv( 'UTF-8','TIS-620',$eachResult["WH1-FG"]),1);
		$this->Cell(18,6,iconv( 'UTF-8','TIS-620',$eachResult["WH3-FG"]),1);
		$this->Cell(18,6,iconv( 'UTF-8','TIS-620',$eachResult["WH1-RENT"]),1);
		$this->Cell(18,6,iconv( 'UTF-8','TIS-620',$eachResult["WH3-RENT"]),1);
		$this->Cell(18,6,iconv( 'UTF-8','TIS-620',$eachResult["WH1-PRO"]),1);
		$this->Cell(18,6,iconv( 'UTF-8','TIS-620',$eachResult["WH3-PRO"]),1);
		$this->Cell(18,6,iconv( 'UTF-8','TIS-620',$eachResult["WH3-RE"]),1);
		$this->Cell(18,6,iconv( 'UTF-8','TIS-620',$eachResult["WH3-REJ"]),1);
		$this->Ln();
	}

	//Closure line
	$this->Cell(array_sum($w),0,'','T');
}

//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(46,18,18,18,18,18,18,18,18);
//	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;
	$n=1;
	foreach($data as $row)

	{
		if ($n % 43 === 1)
		
			{
				$this->AddPage();
				
				
				//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(46,18,18,18,18,18,18,18,18);
				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('');
			}
		$this->Cell($w[0],6,$row[0],'LR',0,'R',$fill);
		$this->Cell($w[1],6,number_format($row[1]),'LR',0,'R',$fill);
		$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
		$this->Cell($w[4],6,number_format($row[3]),'LR',0,'R',$fill);
		$this->Cell($w[5],6,number_format($row[4]),'LR',0,'R',$fill);
		$this->Cell($w[6],6,number_format($row[5]),'LR',0,'R',$fill);
		$this->Cell($w[7],6,number_format($row[6]),'LR',0,'R',$fill);
		$this->Cell($w[8],6,number_format($row[7]),'LR',0,'R',$fill);
		$this->Cell($w[9],6,number_format($row[8]),'LR',0,'R',$fill);
		$this->Ln();
		$fill=!$fill;
		++$n;
	}
	$this->Cell(array_sum($w),0,'','T');
}
}


$pdf=new PDF();

//Column titles
$header=array('Description','WH1-FG','WH3-FG','WH1-RENT','WH3-RENT','WH1-PRO','WH3-PRO','WH3-RE','WH3-REJ');

//Data loading

//*** Load MySQL Data ***//


$objConnect = mssql_connect("192.168.1.3\SQL2005","sa","1234") or die("Error Connect to Database");
$objDB = mssql_select_db("Golive");

$strSQLx = "SELECT 
	T0.ItemCode,
	sum(case T1.WhsCode when 'WH1-FG' then  T1.OnHand else 0 end) as 'WH1-FG',
	sum(case T1.WhsCode when 'WH1-PRO' then  T1.OnHand else 0 end) as 'WH1-PRO',
	sum(case T1.WhsCode when 'WH1-RENT' then  T1.OnHand else 0 end) as 'WH1-RENT',
	sum(case T1.WhsCode when 'WH3-FG' then  T1.OnHand else 0 end) as 'WH3-FG',
	sum(case T1.WhsCode when 'WH3-PRO' then  T1.OnHand else 0 end) as 'WH3-PRO',
	sum(case T1.WhsCode when 'WH3-RE' then  T1.OnHand else 0 end) as 'WH3-RE',
	sum(case T1.WhsCode when 'WH3-REJ' then  T1.OnHand else 0 end) as 'WH3-REJ',
	sum(case T1.WhsCode when 'WH3-RENT' then  T1.OnHand else 0 end) as 'WH3-RENT'
	
	
	FROM 
	OITM T0  INNER JOIN OITW T1 ON T0.ItemCode = T1.ItemCode

	WHERE	
	T1.OnHand <> '0' and T1.WhsCode In ('WH1-FG','WH1-PRO','WH1-RENT','WH3-FG','WH3-PRO','WH3-RE', 'WH3-REJ','WH3-RENT') AND
	(T0.ItmsGrpCod in ('111','104','105')) and (T0.itemCode not like '%FINISHER%' and T0.itemCode not like '%A3%'and T0.itemCode not like '%IMAGEPASS%')

	GROUP BY
	T0.ItemCode
	ORDER by T0.ItemCode";
$objQuery 	= mssql_query($strSQLx) or die ("Error Query [".$strSQLx."]");


$resultData = array();
for ($i=0;$i<mssql_num_rows($objQuery);$i++) {
	$result = mssql_fetch_array($objQuery);
	array_push($resultData,$result);
}


//************************//


$pdf->AddFont('angsa','','angsa.php');
$pdf->AddFont('angsa','B','angsab.php');
$pdf->SetFont('angsa','',10);
$pdf->SetFont('angsa','B',12);

//*** Table 3 ***//
//$pdf->AddPage();
//$pdf->Image('pdf/logo.png',80,8,33);
//$pdf->Ln();
$pdf->FancyTable($header,$resultData);

$pdf->Output("pdf/MyPDF/MyPDF.pdf","F");


// Settings
$name        = "Name goes here";
$email       = "[email protected]";
$to          = "$email";
$from        = "[email protected]";
$subject     = "รายงานเครื่อง สถานะต่างๆ";
$mainMessage = "Hi, here's the file.";
$fileatt     = "pdf/MyPDF/MyPDF.pdf";
$fileatttype = "application/pdf";
$fileattname = "RYG_Item.pdf";
$headers = "From: $from";

// File
$file = fopen($fileatt, 'rb');
$data = fread($file, filesize($fileatt));
fclose($file);

// This attaches the file
$semi_rand     = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers      .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"-{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$mainMessage  . "\n\n";

$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"-{$mime_boundary}-\n";

// Send the email
if(mail($to, $subject, $message, $headers)) {

    echo "The email was sent.";

}
else {

    echo "There was an error sending the mail.";

}

///


//*** Table 1 ***//
//$pdf->AddPage();
//$pdf->Image('pdf/logo.png',80,8,33);
//$pdf->Ln(35);
//$pdf->BasicTable($header,$resultData);

//*** Table 2 ***//
//$pdf->AddPage();
//$pdf->Image('pdf/logo.png',80,8,33);
//$pdf->Ln(35);
//$pdf->ImprovedTable($header,$resultData);


?>
<?
//PDF Created Click <a href="../Production/pdf/MyPDF/MyPDF.pdf">here</a> to Download
?>
</body>
</html>




Tag : PHP, Ms SQL Server 2005







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-01-02 01:35:26 By : karurub View : 1005 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ใช้ตัวนี้จัดรูปแบบยากมากครับ ลองเปลี่ยนไปใช้ mPDF นะครับ สามารถแปลงจาก HTML เป็น PDF ได้ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-01-03 11:56:26 By : mr.win
 


 

No. 2



โพสกระทู้ ( 316 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2016-01-03 11:56:26
รายละเอียดของการตอบ ::

ลองไปใช้แล้ว MPDF มันไม่สามารถเต็มหน้า มันบีบอยู่กลางหน้ากระดาษ แก้ไงดีครับ


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-01-03 23:06:22 By : karurub
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอความช่วยเหลือใน FPDF ให้แสดง Header แบบนี้ต้องเพิ่มยังไงครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่