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 > สอบถามเรื่องออกรายงาน tcpdf แผ่นแรกเป็นกระดาษเปล่าครับ



 

สอบถามเรื่องออกรายงาน tcpdf แผ่นแรกเป็นกระดาษเปล่าครับ

 



Topic : 132574



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



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




Code (PHP)
<?php
session_start();
header("Content-type:text/html; charset=UTF-8");                
header("Cache-Control: no-store, no-cache, must-revalidate");               
header("Cache-Control: post-check=0, pre-check=0", false);    
include("dbconnect.php");
?>
<?php
date_default_timezone_set('Asia/Bangkok');
$date = date("d/m/Y");
$time = time("H:i:s");
?>
<table cellspacing="0" cellpadding="1" border="0" style="width:1000px;">  
<thead>
    <tr>
          <th height="60" colspan="2">&nbsp;BKK GROUP G58&nbsp;</th>
          <th width="129" height="60">&nbsp;</th>
          <th width="141" height="27">&nbsp;</th>
          <th width="134" height="27">&nbsp;</th>
          <th width="133">&nbsp;</th>
          <th width="107" height="27">&nbsp;</th>
          <th width="156" height="27">หน้าที่&nbsp;</th>
        </tr>          
        <tr>
          <th height="28" colspan="2" >&nbsp;โทรศัพท์</th>
          <th height="28" >&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th>&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th height="28">&nbsp;</th>
        </tr>
        <tr>
          <th height="28" colspan="3" >&nbsp;รายงานการสั่งซื้อสินค้าประจำเดือน</th>
          <th height="28">&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th>&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th height="28">&nbsp;</th>
        </tr>
        <tr>
          <th height="28" colspan="2" >&nbsp;วันที่/Date : <?php echo  $date; ?></th>
          <th height="28" colspan="2" >เวลา/Time : <?php echo  $time; ?>&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th>&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th height="28">&nbsp;</th>
        </tr> 
         <tr>
          <th width="50" height="27" align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">รหัสสินค้า</th>
          <th width="100" align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">ราคาสินค้า</th>
          <th width="100" align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">โปรโมชั่น</th>
          <th width="80" align="left "style="border-top:2px solid #000;border-bottom:2px solid #000;">จำนวน</th>
          <th width="100" align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">ราคารวม</th>
          <th width="80" align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">ชื่อลูกค้า</th>
          <th width="80" align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">วันที่</th>
          <th width="100" align="center"style="border-top:2px solid #000;border-bottom:2px solid #000;">พนักงาน</th>
        </tr>
</thead> 
<?php
        $i=1;
        $sql="SELECT * FROM  total WHERE 1  ";
		$result = $mysqli->query($sql);
    	if($result && $result->num_rows>0){ 
		
		while($row = $result->fetch_assoc()){
?>  
  <tr>
        <td width="50" align="center" ><?php echo $row["tcode"];?>&nbsp;</td>
        <td width="100" align="center" ><?php echo number_format($row["tprice"], 2);?>&nbsp;</td>
        <td width="100" align="left" ><?php echo number_format($row["tpro"]);?>&nbsp;</td>
        <td width="80" align="left "><?php echo number_format($row["tunit"], 2);?>&nbsp;</td>
        <td width="100" align="left" ><?php echo number_format($row["tqty"]);?>&nbsp;</td>
        <td width="80" align="left" ><?php echo number_format($row["tname"], 2);?></td>
        <td width="80" align="center" ><?php echo number_format($row["tdate"], 2);?>&nbsp;</td>
        <td width="100" align="center"><?php echo number_format($row["tsave"], 2);?>&nbsp;</td>
  </tr>
     <?php
		$tprice += $row["tprice"]; 
		$tunit += $row["tunit"];
		$tqty += $row["tqty"];
		} 
	
	?>
		
  <tr>
		<td height="5" colspan="8" align="left">&nbsp;</td>
  </tr>
  <tr class=".north_top">
		<td align="center"style="border-top:2px solid #000;border-bottom:2px solid #000;">รวม&nbsp;</td>
		<td align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;"><?php echo number_format($tprice, 2);?>&nbsp;</td>
		<td align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo number_format($tunit, 2);?>&nbsp;</td>
		<td align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">&nbsp;</td>
		<td align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo number_format($tqty, 2);?>&nbsp;</td>
		<td align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">&nbsp;</td>
		<td align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">&nbsp;</td>
		<td align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">&nbsp;</td>
  </tr>
<?php $i++; } ?>     
</table>


Code (PHP)
<?php
// Include the main TCPDF library (search for installation path).
require_once('tcpdf/tcpdf.php');
include("tcpdf/class/class_curl.php");

// การตั้งค่าข้อความ ที่เกี่ยวข้องให้ดูในไฟล์  tcpdf / config /  tcpdf_config.php 
// เริ่มสร้างไฟล์ pdf
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// กำหนดรายละเอียดของไฟล์ pdf
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('BKK GROUP');
$pdf->SetTitle('TCPDF table report');
$pdf->SetSubject('TCPDF ทดสอบ');
$pdf->SetKeywords('TCPDF, PDF, ทดสอบ,ninenik, guide');

$pdf->setFooterData(
    array(0,64,0),  // กำหนดสีของข้อความใน footer rgb 
    array(220,44,44)   // กำหนดสีของเส้นคั่นใน footer rgb 
);
// กำหนดขอบเขตความห่างจากขอบ  กำหนดเพิ่มเติมในไฟล์  tcpdf_config.php 
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// กำหนดแบ่่งหน้าอัตโนมัติ
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// กำหนดสัดส่วนของรูปภาพ  กำหนดเพิ่มเติมในไฟล์  tcpdf_config.php 
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// อนุญาตให้สามารถกำหนดรุปแบบ ฟอนท์ย่อยเพิมเติมในหน้าใช้งานได้
$pdf->setFontSubsetting(true);

// กำหนด ฟอนท์
$pdf->SetFont('thsarabun', '', 14, '', true);

// เพิ่มหน้า 
$pdf->AddPage();

$path_info = pathinfo($_SERVER['REQUEST_URI']);
$http = ($_SERVER['REQUEST_SCHEME'])?$_SERVER['REQUEST_SCHEME']."://":"http://";
$host = $_SERVER['SERVER_NAME'];
$pathDir = $path_info['dirname']."/";
$url = $http.$host.$pathDir;

// เรียกใช้งาน ฟังก์ชั่นดึงข้อมูลไฟล์มาใช้งาน
$html = curl_get($url."total.php"); // path ไฟล์ 

// สร้าง pdf ด้วยคำสั่ง writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);

// แสดงไฟล์ pdf
$pdf->Output('I');
?>




Tag : PHP, MySQL









ประวัติการแก้ไข
2018-11-17 14:38:57
2018-11-20 08:53:14
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2018-11-17 14:37:12 By : HLEW View : 1102 Reply : 7
 

 

No. 1



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

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

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


ลองเปลี่ยน page ดูครับมันมีให้เลือกหลายตัว

ไม่งั้นลองเอา PDF_MARGIN_TOP ออกดู






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-11-17 19:33:38 By : Pong Thep
 


 

No. 2



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



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


ตอบความคิดเห็นที่ : 1 เขียนโดย : Pong Thep เมื่อวันที่ 2018-11-17 19:33:38
รายละเอียดของการตอบ ::
ตอนนี้แก้ได้แล้วครับ เหลือจัดตำแหน่งของเลขหน้าครับ


รบกวนท่านที่รู้ช่วยหน่อยชี้แนะหน่อยครับ คือผมอยากให้อยู่ตำแหน่งของกรอบสีแดงครับ

Code (PHP)
$this->Cell(0, 0, 'หน้าที่ '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');


5555


ประวัติการแก้ไข
2018-11-19 09:51:04
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-11-19 09:50:03 By : HLEW
 

 

No. 3



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



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


ตอนนี้แผ่นแรกออกกระดาษเปล่าครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-11-20 08:54:49 By : HLEW
 


 

No. 4



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



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


ผมลองแก้ไขแล้วเป็นแบบนี้ครับ แผ่นแรกมานะครับแต่แทนที่จะออกทีละสอง กลายเป็นว่าออกอันเดียว แล้วแผ่นที่สองถึงออกเป็นทีละสอง

5555

Code (PHP)
<?php
session_start();
header("Content-type:text/html; charset=UTF-8");                
header("Cache-Control: no-store, no-cache, must-revalidate");               
header("Cache-Control: post-check=0, pre-check=0", false);    
include("dbconnect.php");
?>
<style type="text/css">
@media all
{
    .page-break { display:none; }
    .page-break-no{ display:none; }
}
@media print
{
	.page-break { display:block;height:1px; page-break-before:always; }
    .page-break-no{ display:block;height:1px; page-break-after:avoid; } 
}
.dotted_bottom {
    border-bottom:1px dotted;
}
.north_top {
	border-top:2px solid #000;
	border-bottom:2px solid #000;
}
</style>
<?php
		date_default_timezone_set('Asia/Bangkok');
		$date = date("d/m/Y");
		$time = date("H:i:s");

        
        $sql="SELECT * FROM  total ";
		$result = $mysqli->query($sql);
    	if($result && $result->num_rows>0){ 
		$i=1;
		while($row = $result->fetch_assoc()){
?>
<div class="page-break<?=(($i%2)==0)?"-no":""?>">&nbsp;</div> 
<table cellspacing="0" cellpadding="1" border="0" style="width:1000px;">  
<thead>
    <tr>
          <th height="60" colspan="2">&nbsp;BKK GROUP G58&nbsp;</th>
          <th width="129" height="60">&nbsp;</th>
          <th width="141" height="27">&nbsp;</th>
          <th width="134" height="27">&nbsp;</th>
          <th width="133">&nbsp;</th>
          <th width="107" height="27">&nbsp;</th>
          <th width="156" height="27">หน้าที่<?=$i;?>&nbsp;</th>
        </tr>          
        <tr>
          <th height="28" colspan="2" >&nbsp;โทรศัพท์</th>
          <th height="28" >&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th>&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th height="28">&nbsp;</th>
        </tr>
        <tr>
          <th height="28" colspan="3" >&nbsp;รายงานการสั่งซื้อสินค้าประจำเดือน</th>
          <th height="28">&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th>&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th height="28">&nbsp;</th>
        </tr>
        <tr>
          <th height="28" colspan="2" >&nbsp;วันที่/Date : <?php echo  $date; ?></th>
          <th height="28" colspan="2" >เวลา/Time : <?php echo  $time; ?>&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th>&nbsp;</th>
          <th height="28">&nbsp;</th>
          <th height="28">&nbsp;</th>
        </tr> 
         <tr>
          <th width="50" height="27" align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">รหัสสินค้า</th>
          <th width="100" align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">ราคาสินค้า</th>
          <th width="100" align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">โปรโมชั่น</th>
          <th width="80" align="left "style="border-top:2px solid #000;border-bottom:2px solid #000;">จำนวน</th>
          <th width="100" align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">ราคารวม</th>
          <th width="80" align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">ชื่อลูกค้า</th>
          <th width="80" align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">วันที่</th>
          <th width="100" align="center"style="border-top:2px solid #000;border-bottom:2px solid #000;">พนักงาน</th>
        </tr>
</thead> 
 
  <tr>
        <td width="50" align="center" ><?php echo $row["tcode"];?>&nbsp;</td>
        <td width="100" align="center" ><?php echo number_format($row["tprice"], 2);?>&nbsp;</td>
        <td width="100" align="left" ><?php echo number_format($row["tpro"]);?>&nbsp;</td>
        <td width="80" align="left "><?php echo number_format($row["tunit"], 2);?>&nbsp;</td>
        <td width="100" align="left" ><?php echo number_format($row["tqty"]);?>&nbsp;</td>
        <td width="80" align="left" ><?php echo number_format($row["tname"], 2);?></td>
        <td width="80" align="center" ><?php echo number_format($row["tdate"], 2);?>&nbsp;</td>
        <td width="100" align="center"><?php echo number_format($row["tsave"], 2);?>&nbsp;</td>
  </tr>     
		<?php $i++; } }?>     
</table>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-11-20 11:15:09 By : HLEW
 


 

No. 5



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



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


<div class="page-break<?=(($i%2)==0)?"-no":""?>">&nbsp;</div>

ข้างบน ย้านไปหลัง table
แล้ว เปลี่ยน ($i%2)==0 เป็น ($i%2)>0

เพราะ array index จะเริ่มจาก 0 (เลขคู่) ดังนั้น พอ เป็นคี่ แสดง คู่ + คี่ เสร็จขึ้นหน้าใหม่

ถ้าตรวจสอบว่าเป็น รายการสุดท้ายก็ไม่ต้องขึ้น pagebreak ด้วยก็จะไม่มีหน้าว่างหน้าสุดท้าย
ลองคิดเอาเองนะครับ พอรู้ปัญหา คงไม่เกินความสามารถ


ประวัติการแก้ไข
2018-11-20 12:43:29
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-11-20 12:41:47 By : Chaidhanan
 


 

No. 6



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



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


ขอบคุณมากครับผม ตอนแรกผมนึกว่า โปรแกรม PDF จะใช้งานง่ายก็ยากเหมือนกัน
ตอนนี้ มีปัญหากับรีพอร์ตหลายหน้าเพราะขนาดรีพอร์ตแต่ละตัวไม่เท่ากัน พอไปแก้ไขไฟล์ tcpdf_config.php
พอมีตัวอย่างไหมครับคือผมจะแยก tcpdf_config.php เป็นของแต่ละรีพอร์ต
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-11-20 14:29:47 By : HLEW
 


 

No. 7



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



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


Code (PHP)
$include_id = 1; // ตรวจสอบและกำหนดค่าตามที่จะเป็นเพื่อ กำหนด config
include ('file_config_'.$include_id.'.php');// ไฟล์ config ที่ต้องการ
include('tcpdf.php');
$pdf=new tcpdf_library();

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-11-20 15:36:30 By : Chaidhanan
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามเรื่องออกรายงาน tcpdf แผ่นแรกเป็นกระดาษเปล่าครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 อัตราราคา คลิกที่นี่