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,038

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


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

 
Topic : 132574



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



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



Code (PHP)
001.<?php
002.session_start();
003.header("Content-type:text/html; charset=UTF-8");               
004.header("Cache-Control: no-store, no-cache, must-revalidate");              
005.header("Cache-Control: post-check=0, pre-check=0", false);   
006.include("dbconnect.php");
007.?>
008.<?php
009.date_default_timezone_set('Asia/Bangkok');
010.$date = date("d/m/Y");
011.$time = time("H:i:s");
012.?>
013.<table cellspacing="0" cellpadding="1" border="0" style="width:1000px;"
014.<thead>
015.    <tr>
016.          <th height="60" colspan="2">&nbsp;BKK GROUP G58&nbsp;</th>
017.          <th width="129" height="60">&nbsp;</th>
018.          <th width="141" height="27">&nbsp;</th>
019.          <th width="134" height="27">&nbsp;</th>
020.          <th width="133">&nbsp;</th>
021.          <th width="107" height="27">&nbsp;</th>
022.          <th width="156" height="27">หน้าที่&nbsp;</th>
023.        </tr>         
024.        <tr>
025.          <th height="28" colspan="2" >&nbsp;โทรศัพท์</th>
026.          <th height="28" >&nbsp;</th>
027.          <th height="28">&nbsp;</th>
028.          <th height="28">&nbsp;</th>
029.          <th>&nbsp;</th>
030.          <th height="28">&nbsp;</th>
031.          <th height="28">&nbsp;</th>
032.        </tr>
033.        <tr>
034.          <th height="28" colspan="3" >&nbsp;รายงานการสั่งซื้อสินค้าประจำเดือน</th>
035.          <th height="28">&nbsp;</th>
036.          <th height="28">&nbsp;</th>
037.          <th>&nbsp;</th>
038.          <th height="28">&nbsp;</th>
039.          <th height="28">&nbsp;</th>
040.        </tr>
041.        <tr>
042.          <th height="28" colspan="2" >&nbsp;วันที่/Date : <?php echo  $date; ?></th>
043.          <th height="28" colspan="2" >เวลา/Time : <?php echo  $time; ?>&nbsp;</th>
044.          <th height="28">&nbsp;</th>
045.          <th>&nbsp;</th>
046.          <th height="28">&nbsp;</th>
047.          <th height="28">&nbsp;</th>
048.        </tr>
049.         <tr>
050.          <th width="50" height="27" align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">รหัสสินค้า</th>
051.          <th width="100" align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">ราคาสินค้า</th>
052.          <th width="100" align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">โปรโมชั่น</th>
053.          <th width="80" align="left "style="border-top:2px solid #000;border-bottom:2px solid #000;">จำนวน</th>
054.          <th width="100" align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">ราคารวม</th>
055.          <th width="80" align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">ชื่อลูกค้า</th>
056.          <th width="80" align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">วันที่</th>
057.          <th width="100" align="center"style="border-top:2px solid #000;border-bottom:2px solid #000;">พนักงาน</th>
058.        </tr>
059.</thead>
060.<?php
061.        $i=1;
062.        $sql="SELECT * FROM  total WHERE 1  ";
063.        $result = $mysqli->query($sql);
064.        if($result && $result->num_rows>0){
065.         
066.        while($row = $result->fetch_assoc()){
067.?> 
068.  <tr>
069.        <td width="50" align="center" ><?php echo $row["tcode"];?>&nbsp;</td>
070.        <td width="100" align="center" ><?php echo number_format($row["tprice"], 2);?>&nbsp;</td>
071.        <td width="100" align="left" ><?php echo number_format($row["tpro"]);?>&nbsp;</td>
072.        <td width="80" align="left "><?php echo number_format($row["tunit"], 2);?>&nbsp;</td>
073.        <td width="100" align="left" ><?php echo number_format($row["tqty"]);?>&nbsp;</td>
074.        <td width="80" align="left" ><?php echo number_format($row["tname"], 2);?></td>
075.        <td width="80" align="center" ><?php echo number_format($row["tdate"], 2);?>&nbsp;</td>
076.        <td width="100" align="center"><?php echo number_format($row["tsave"], 2);?>&nbsp;</td>
077.  </tr>
078.     <?php
079.        $tprice += $row["tprice"];
080.        $tunit += $row["tunit"];
081.        $tqty += $row["tqty"];
082.        }
083.     
084.    ?>
085.         
086.  <tr>
087.        <td height="5" colspan="8" align="left">&nbsp;</td>
088.  </tr>
089.  <tr class=".north_top">
090.        <td align="center"style="border-top:2px solid #000;border-bottom:2px solid #000;">รวม&nbsp;</td>
091.        <td align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;"><?php echo number_format($tprice, 2);?>&nbsp;</td>
092.        <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>
093.        <td align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">&nbsp;</td>
094.        <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>
095.        <td align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">&nbsp;</td>
096.        <td align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">&nbsp;</td>
097.        <td align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">&nbsp;</td>
098.  </tr>
099.<?php $i++; } ?>    
100.</table>


Code (PHP)
01.<?php
02.// Include the main TCPDF library (search for installation path).
03.require_once('tcpdf/tcpdf.php');
04.include("tcpdf/class/class_curl.php");
05. 
06.// การตั้งค่าข้อความ ที่เกี่ยวข้องให้ดูในไฟล์  tcpdf / config /  tcpdf_config.php
07.// เริ่มสร้างไฟล์ pdf
08.$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
09. 
10.// กำหนดรายละเอียดของไฟล์ pdf
11.$pdf->SetCreator(PDF_CREATOR);
12.$pdf->SetAuthor('BKK GROUP');
13.$pdf->SetTitle('TCPDF table report');
14.$pdf->SetSubject('TCPDF ทดสอบ');
15.$pdf->SetKeywords('TCPDF, PDF, ทดสอบ,ninenik, guide');
16. 
17.$pdf->setFooterData(
18.    array(0,64,0),  // กำหนดสีของข้อความใน footer rgb
19.    array(220,44,44)   // กำหนดสีของเส้นคั่นใน footer rgb
20.);
21.// กำหนดขอบเขตความห่างจากขอบ  กำหนดเพิ่มเติมในไฟล์  tcpdf_config.php
22.$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
23.$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
24.$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
25. 
26.// กำหนดแบ่่งหน้าอัตโนมัติ
27.$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
28. 
29.// กำหนดสัดส่วนของรูปภาพ  กำหนดเพิ่มเติมในไฟล์  tcpdf_config.php
30.$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
31. 
32.// อนุญาตให้สามารถกำหนดรุปแบบ ฟอนท์ย่อยเพิมเติมในหน้าใช้งานได้
33.$pdf->setFontSubsetting(true);
34. 
35.// กำหนด ฟอนท์
36.$pdf->SetFont('thsarabun', '', 14, '', true);
37. 
38.// เพิ่มหน้า
39.$pdf->AddPage();
40. 
41.$path_info = pathinfo($_SERVER['REQUEST_URI']);
42.$http = ($_SERVER['REQUEST_SCHEME'])?$_SERVER['REQUEST_SCHEME']."://":"http://";
43.$host = $_SERVER['SERVER_NAME'];
44.$pathDir = $path_info['dirname']."/";
45.$url = $http.$host.$pathDir;
46. 
47.// เรียกใช้งาน ฟังก์ชั่นดึงข้อมูลไฟล์มาใช้งาน
48.$html = curl_get($url."total.php"); // path ไฟล์
49. 
50.// สร้าง pdf ด้วยคำสั่ง writeHTMLCell()
51.$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
52. 
53.// แสดงไฟล์ pdf
54.$pdf->Output('I');
55.?>




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 : 1250 Reply : 7
 

 

No. 1



โพสกระทู้ ( 1,096 )
บทความ ( 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)
1.$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)
001.<?php
002.session_start();
003.header("Content-type:text/html; charset=UTF-8");               
004.header("Cache-Control: no-store, no-cache, must-revalidate");              
005.header("Cache-Control: post-check=0, pre-check=0", false);   
006.include("dbconnect.php");
007.?>
008.<style type="text/css">
009.@media all
010.{
011.    .page-break { display:none; }
012.    .page-break-no{ display:none; }
013.}
014.@media print
015.{
016.    .page-break { display:block;height:1px; page-break-before:always; }
017.    .page-break-no{ display:block;height:1px; page-break-after:avoid; }
018.}
019..dotted_bottom {
020.    border-bottom:1px dotted;
021.}
022..north_top {
023.    border-top:2px solid #000;
024.    border-bottom:2px solid #000;
025.}
026.</style>
027.<?php
028.        date_default_timezone_set('Asia/Bangkok');
029.        $date = date("d/m/Y");
030.        $time = date("H:i:s");
031. 
032.         
033.        $sql="SELECT * FROM  total ";
034.        $result = $mysqli->query($sql);
035.        if($result && $result->num_rows>0){
036.        $i=1;
037.        while($row = $result->fetch_assoc()){
038.?>
039.<div class="page-break<?=(($i%2)==0)?"-no":""?>">&nbsp;</div>
040.<table cellspacing="0" cellpadding="1" border="0" style="width:1000px;"
041.<thead>
042.    <tr>
043.          <th height="60" colspan="2">&nbsp;BKK GROUP G58&nbsp;</th>
044.          <th width="129" height="60">&nbsp;</th>
045.          <th width="141" height="27">&nbsp;</th>
046.          <th width="134" height="27">&nbsp;</th>
047.          <th width="133">&nbsp;</th>
048.          <th width="107" height="27">&nbsp;</th>
049.          <th width="156" height="27">หน้าที่<?=$i;?>&nbsp;</th>
050.        </tr>         
051.        <tr>
052.          <th height="28" colspan="2" >&nbsp;โทรศัพท์</th>
053.          <th height="28" >&nbsp;</th>
054.          <th height="28">&nbsp;</th>
055.          <th height="28">&nbsp;</th>
056.          <th>&nbsp;</th>
057.          <th height="28">&nbsp;</th>
058.          <th height="28">&nbsp;</th>
059.        </tr>
060.        <tr>
061.          <th height="28" colspan="3" >&nbsp;รายงานการสั่งซื้อสินค้าประจำเดือน</th>
062.          <th height="28">&nbsp;</th>
063.          <th height="28">&nbsp;</th>
064.          <th>&nbsp;</th>
065.          <th height="28">&nbsp;</th>
066.          <th height="28">&nbsp;</th>
067.        </tr>
068.        <tr>
069.          <th height="28" colspan="2" >&nbsp;วันที่/Date : <?php echo  $date; ?></th>
070.          <th height="28" colspan="2" >เวลา/Time : <?php echo  $time; ?>&nbsp;</th>
071.          <th height="28">&nbsp;</th>
072.          <th>&nbsp;</th>
073.          <th height="28">&nbsp;</th>
074.          <th height="28">&nbsp;</th>
075.        </tr>
076.         <tr>
077.          <th width="50" height="27" align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">รหัสสินค้า</th>
078.          <th width="100" align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">ราคาสินค้า</th>
079.          <th width="100" align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">โปรโมชั่น</th>
080.          <th width="80" align="left "style="border-top:2px solid #000;border-bottom:2px solid #000;">จำนวน</th>
081.          <th width="100" align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">ราคารวม</th>
082.          <th width="80" align="left" style="border-top:2px solid #000;border-bottom:2px solid #000;">ชื่อลูกค้า</th>
083.          <th width="80" align="center" style="border-top:2px solid #000;border-bottom:2px solid #000;">วันที่</th>
084.          <th width="100" align="center"style="border-top:2px solid #000;border-bottom:2px solid #000;">พนักงาน</th>
085.        </tr>
086.</thead>
087.  
088.  <tr>
089.        <td width="50" align="center" ><?php echo $row["tcode"];?>&nbsp;</td>
090.        <td width="100" align="center" ><?php echo number_format($row["tprice"], 2);?>&nbsp;</td>
091.        <td width="100" align="left" ><?php echo number_format($row["tpro"]);?>&nbsp;</td>
092.        <td width="80" align="left "><?php echo number_format($row["tunit"], 2);?>&nbsp;</td>
093.        <td width="100" align="left" ><?php echo number_format($row["tqty"]);?>&nbsp;</td>
094.        <td width="80" align="left" ><?php echo number_format($row["tname"], 2);?></td>
095.        <td width="80" align="center" ><?php echo number_format($row["tdate"], 2);?>&nbsp;</td>
096.        <td width="100" align="center"><?php echo number_format($row["tsave"], 2);?>&nbsp;</td>
097.  </tr>    
098.        <?php $i++; } }?>    
099.</table>

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

 

No. 5



โพสกระทู้ ( 9,590 )
บทความ ( 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,590 )
บทความ ( 2 )



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


Code (PHP)
1.$include_id = 1; // ตรวจสอบและกำหนดค่าตามที่จะเป็นเพื่อ กำหนด config
2.include ('file_config_'.$include_id.'.php');// ไฟล์ config ที่ต้องการ
3.include('tcpdf.php');
4.$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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





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