|
|
|
ขอสอบถามครับ ผมลองใช้ MPDF มาแปลง HTML เป็น PHP ผลปรากฏว่ามันแสดงออกมาไม่เต็มจอ |
|
|
|
|
|
|
|
ขอสอบถามครับ ผมลองใช้ MPDF มาแปลง HTML เป็น PDF ผลปรากฏว่ามันแสดงออกมาไม่เต็มหน้ากระดาษตามรูป ต้องทำยังไงครับ
Code (PHP)
<?
session_start();
include "include/connect.php";
require_once('mpdf/mpdf.php');
ob_start();
if($sess_dittoid<>session_id()){
header("location:index.html");exit();
}
else{
$objDB = mysql_select_db("$dbname");
$ck_id = $_SESSION['uid_idx'];
$strSQL="select * from `ditto_report_userauthen` inner join `ditto_report_group` on ref_authen_group = group_id inner join `ditto_report_authen` on ref_group_id = group_id inner join `ditto_report` on report_no = ref_report_id where ref_user = '$ck_id' and au_status = '1' and report_status = '1' and ref_report_id = '23'";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$rs=mysql_fetch_array($objQuery);
$Num_Rows = mysql_num_rows($objQuery);
if ($Num_Rows < 1){
$code_error="<FONT COLOR=\"red\">คุณไม่มีสิทธิ์เข้าดูหน้านี้</FONT>";
session_register("code_error");
header("location:../../report.php");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<style type="text/css">
<!--
@page rotated { size: landscape; }
.style1 {
font-family: "TH SarabunPSK";
font-size: 18pt;
font-weight: bold;
}
.style2 {
font-family: "TH SarabunPSK";
font-size: 16pt;
font-weight: bold;
}
.style3 {
font-family: "TH SarabunPSK";
font-size: 16pt;
}
.style5 {cursor: hand; font-weight: normal; color: #000000;}
.style9 {font-family: Tahoma; font-size: 12px; }
.style11 {font-size: 12px}
.style13 {font-size: 9}
.style16 {font-size: 9; font-weight: bold; }
.style17 {font-size: 12px; font-weight: bold; }
@page :right {
margin-top: 3cm;
margin-bottom: 4cm;
header: html_myHeader;
margin-left: 1cm;
margin-right: 1cm;
}
-->
</style>
<style type="text/css">
<!--
body {
background-color: #CCC;
}
/* the div that holds the date picker calendar */
.dpDiv {
}
/* the table (within the div) that holds the date picker calendar */
.dpTable {
font-family: Tahoma, Arial, Helvetica, sans-serif;
font-size: 12px;
text-align: center;
color: #505050;
background-color: #ece9d8;
border: 1px solid #AAAAAA;
}
/* a table row that holds date numbers (either blank or 1-31) */
.dpTR {
}
/* the top table row that holds the month, year, and forward/backward buttons */
.dpTitleTR {
}
/* the second table row, that holds the names of days of the week (Mo, Tu, We, etc.) */
.dpDayTR {
}
/* the bottom table row, that has the "This Month" and "Close" buttons */
.dpTodayButtonTR {
}
/* a table cell that holds a date number (either blank or 1-31) */
.dpTD {
border: 1px solid #ece9d8;
}
/* a table cell that holds a highlighted day (usually either today's date or the current date field value) */
.dpDayHighlightTD {
background-color: #CCCCCC;
border: 1px solid #AAAAAA;
}
/* the date number table cell that the mouse pointer is currently over (you can use contrasting colors to make it apparent which cell is being hovered over) */
.dpTDHover {
background-color: #aca998;
border: 1px solid #888888;
cursor: pointer;
color: red;
}
/* the table cell that holds the name of the month and the year */
.dpTitleTD {
}
/* a table cell that holds one of the forward/backward buttons */
.dpButtonTD {
}
/* the table cell that holds the "This Month" or "Close" button at the bottom */
.dpTodayButtonTD {
}
/* a table cell that holds the names of days of the week (Mo, Tu, We, etc.) */
.dpDayTD {
background-color: #CCCCCC;
border: 1px solid #AAAAAA;
color: white;
}
/* additional style information for the text that indicates the month and year */
.dpTitleText {
font-size: 12px;
color: gray;
font-weight: bold;
}
/* additional style information for the cell that holds a highlighted day (usually either today's date or the current date field value) */
.dpDayHighlight {
color: 4060ff;
font-weight: bold;
}
/* the forward/backward buttons at the top */
.dpButton {
font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif;
font-size: 10px;
color: gray;
background: #d8e8ff;
font-weight: bold;
padding: 0px;
}
/* the "This Month" and "Close" buttons at the bottom */
.dpTodayButton {
font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif;
font-size: 10px;
color: gray;
background: #d8e8ff;
font-weight: bold;
}
.style7 {font-size: 12px; font-weight: bold;}
.style8 {font-size: 10px;font-weight: bold}
.style9 {font-size: 10px; font-weight: bold;color: #000000;}
.style10 {font-size: 12px; font-weight: bold;color: #000000; }
.style13 {font-size: 14px; color: #FFFFFF; font-weight: bold; }
.style14 {font-size: 14px; color: #FFFFFF; font-weight: bold; }
a:link {
color: #000;
text-decoration: none;
}
a:visited {
color: #000;
text-decoration: none;
}
a:hover {
color: #000;
text-decoration: none;
}
a:active {
color: #000;
text-decoration: none;
}
-->
</style>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" width="900" align="center" height="900" bgcolor="#FFFFFF">
<tr>
<td width="100%" align="center" valign="top">
<?
$strSQL =
"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 = odbc_exec($cid,$strSQL) or die ("Error Query [".$strSQL."]");
while($objResultx = odbc_fetch_array($objQuery))
//while($objResult = mssql_fetch_array($objQuery) && $objResult2 = mssql_fetch_array($objQuery2))
{
$intTotal_WH1_FGx = $intTotal_WH1_FGx + $objResultx["WH1-FG"];
$intTotal_WH1_PROx = $intTotal_WH1_PROx + $objResultx["WH1-PRO"];
$intTotal_WH1_RENTx = $intTotal_WH1_RENTx + $objResultx["WH1-RENT"];
$intTotal_WH3_FGx = $intTotal_WH3_FGx + $objResultx["WH3-FG"];
$intTotal_WH3_PROx = $intTotal_WH3_PROx + $objResultx["WH3-PRO"];
$intTotal_WH3_REx = $intTotal_WH3_REx + $objResultx["WH3-RE"];
$intTotal_WH3_REJx = $intTotal_WH3_REJx + $objResultx["WH3-REJ"];
$intTotal_WH3_RENTx = $intTotal_WH3_RENTx + $objResultx["WH3-RENT"];
}
?>
<br />
<table width="900" border="1" align="left" cellspacing="0" bordercolor="#000000" bgcolor="#0033FF">
<tr>
<th width="18" rowspan="2" bgcolor="#0000FF"> <div align="center" class="style13">No.</div></th>
<th width="120" rowspan="2" bgcolor="#0000FF"> <div align="center" class="style13">Description</div></th>
<th colspan="2" bgcolor="#FFFFFF"><div align="center">FG</div></th>
<th colspan="2" bgcolor="#FFFFFF"><div align="center">RENT</div></th>
<th colspan="2" bgcolor="#00FF00"><div align="center">GREEN</div></th>
<th bgcolor="#FFFF00"><div align="center">YELLOW</div></th>
<th bgcolor="#FF0000">RED</th>
</tr>
<tr>
<th width="64"><span class="style14">WH1-FG</span></th>
<th width="64"><span class="style14">WH3-FG</span></th>
<th width="64"><span class="style14">WH1-RENT</span></th>
<th width="64"><span class="style14">WH3-RENT</span></th>
<th width="64"><span class="style14">WH1-PRO</span></th>
<th width="64"><span class="style14">WH3-PRO</span></th>
<th width="64"><span class="style14">WH3-RE</span></th>
<th width="64"><span class="style14">WH3-REJ</span></th>
</tr>
<?
$i=1;
$j=1;
$intTotal_WH1_FG = 0;
$intTotal_WH1_PRO = 0;
$intTotal_WH1_RENT = 0;
$intTotal_WH3_FG = 0;
$intTotal_WH3_PRO = 0;
$intTotal_WH3_RE = 0;
$intTotal_WH3_REJ = 0;
$intTotal_WH3_RENT = 0;
$objQueryx = odbc_exec($cid,$strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = odbc_fetch_array($objQueryx))
{
$intTotal_WH1_FG = $intTotal_WH1_FG + $objResult["WH1-FG"];
$intTotal_WH1_PRO = $intTotal_WH1_PRO + $objResult["WH1-PRO"];
$intTotal_WH1_RENT = $intTotal_WH1_RENT + $objResult["WH1-RENT"];
$intTotal_WH3_FG = $intTotal_WH3_FG + $objResult["WH3-FG"];
$intTotal_WH3_PRO = $intTotal_WH3_PRO + $objResult["WH3-PRO"];
$intTotal_WH3_RE = $intTotal_WH3_RE + $objResult["WH3-RE"];
$intTotal_WH3_REJ = $intTotal_WH3_REJ + $objResult["WH3-REJ"];
$intTotal_WH3_RENT = $intTotal_WH3_RENT + $objResult["WH3-RENT"];
$j++;
if($j%2==0)
{
$bg = "#99CCFF";
}
else
{
$bg = "#FFFFFF";
}
?>
<tr bgcolor="<?=$bg;?>">
<td><div align="center" class="style8"><?=$i;?></div></td>
<td><span class="style8"><a href="menufsn.php?itemcode=<?=$objResult["ItemCode"];?>"><?=$objResult["ItemCode"];?></a></span></td>
<td><div align="right"><span class="style8">
<? if(number_format(substr($objResult["WH1-FG"],0,-4),2) =='0')
{
echo "<font color=\"red\">-</font>";
}
else
{
echo number_format(substr($objResult["WH1-FG"],0,-4),2);
}
?></span></div></td>
<td><div align="right"><span class="style8">
<? if(number_format(substr($objResult["WH3-FG"],0,-4),2) =='0')
{
echo "<font color=\"red\">-</font>";
}
else
{
echo number_format(substr($objResult["WH3-FG"],0,-4),2);
}
?>
</span></div></td>
<td><div align="right"><span class="style8">
<? if(number_format(substr($objResult["WH1-RENT"],0,-4),2) =='0')
{
echo "<font color=\"red\">-</font>";
}
else
{
echo number_format(substr($objResult["WH1-RENT"],0,-4),2);
}
?>
</span></div></td>
<td><div align="right"><span class="style8">
<? if(number_format(substr($objResult["WH3-RENT"],0,-4),2) =='0')
{
echo "<font color=\"red\">-</font>";
}
else
{
echo number_format(substr($objResult["WH3-RENT"],0,-4),2);
}
?>
</span></div></td>
<td><div align="right"><span class="style8">
<? if(number_format(substr($objResult["WH1-PRO"],0,-4),2) =='0')
{
echo "<font color=\"red\">-</font>";
}
else
{
echo number_format(substr($objResult["WH1-PRO"],0,-4),2);
}
?>
</span></div></td>
<td><div align="right"><span class="style8">
<? if(number_format(substr($objResult["WH3-PRO"],0,-4),2) =='0')
{
echo "<font color=\"red\">-</font>";
}
else
{
echo number_format(substr($objResult["WH3-PRO"],0,-4),2);
}
?>
</span></div></td>
<td><div align="right"><span class="style8">
<? if(number_format(substr($objResult["WH3-RE"],0,-4),2) =='0')
{
echo "<font color=\"red\">-</font>";
}
else
{
echo number_format(substr($objResult["WH3-RE"],0,-4),2);
}
?>
</span></div></td>
<td><div align="right"><span class="style8">
<? if(number_format(substr($objResult["WH3-REJ"],0,-4),2) =='0')
{
echo "<font color=\"red\">-</font>";
}
else
{
echo number_format(substr($objResult["WH3-REJ"],0,-4),2);
}
?>
</span></div></td>
</tr>
<?
$i++;
}
?>
<tr>
<th colspan="2" rowspan="3" bgcolor="#FFCC33">Total</th>
<th colspan="2" bgcolor="#FFFFFF"><div align="center">FG</div></th>
<th colspan="2" bgcolor="#FFFFFF"><div align="center">RENT</div></th>
<th colspan="2" bgcolor="#00FF00"><div align="center">GREEN</div></th>
<th bgcolor="#FFFF00"><div align="center">YELLOW</div></th>
<th bgcolor="#FF0000">RED</th>
</tr>
<tr>
<th width="64"><span class="style14">WH1-FG</span></th>
<th width="64"><span class="style14">WH3-FG</span></th>
<th width="64"><span class="style14">WH1-RENT</span></th>
<th width="64"><span class="style14">WH3-RENT</span></th>
<th width="64"><span class="style14">WH1-PRO</span></th>
<th width="64"><span class="style14">WH3-PRO</span></th>
<th width="64"><span class="style14">WH3-RE</span></th>
<th width="64"><span class="style14">WH3-REJ</span></th>
</tr>
<tr bgcolor="#FFCC33">
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_WH1_FG,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_WH3_FG,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_WH1_RENT,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_WH3_RENT,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_WH1_PRO,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_WH3_PRO,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_WH3_RE,2);?>
</div></td>
<td nowrap="nowrap"><div align="right" class="style15">
<?=number_format($intTotal_WH3_REJ,2);?>
</div></td>
</tr>
<tr>
<th colspan="2" bgcolor="#FFCC33"><div align="center">รวม</div></th>
<th colspan="8" bgcolor="#CC66FF"><? $intTotal = $intTotal_WH1_FG+$intTotal_WH3_FG+$intTotal_WH1_RENT+$intTotal_WH3_RENT+$intTotal_WH1_PRO+$intTotal_WH3_PRO+$intTotal_WH3_RE+$intTotal_WH3_REJ; echo number_format($intTotal,2);?></th>
</tr>
</table> </td>
</tr>
</table>
<?
odbc_close($cid);
?>
</body>
</html>
<?Php
$html = ob_get_contents();
ob_end_clean();
$pdf = new mPDF('th', 'A4', '0', 'THSaraban');
$pdf->SetAutoFont();
$pdf->SetDisplayMode('fullpage');
$pdf->WriteHTML($html, 2);
$pdf->Output("pdf/MyPDF/MyPDF.pdf","F");
?>
Tag : PHP, Ms SQL Server 2005
|
ประวัติการแก้ไข 2016-01-04 01:40:22 2016-01-04 01:41:03
|
|
|
|
|
Date :
2016-01-04 01:39:47 |
By :
karurub |
View :
1893 |
Reply :
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ก็คุณกำหนด table width ไว้ที่ 900 มันจะเต็มได้ยังไงล่ะครับ?
นี่คุณเขียนเองป่าวเนี่ย โค้ดนี้
stylesheet ก็ดันอยู่นอก <head>
แถมหลายๆตัวไม่รู้เขียนกำหนดทำไม ไม่มี class นั้นๆใน html เลยสักกะหน่อย มีไว้ให้มันเปลืองทรัพยากรในการประมวลผลของ mpdf เล่นๆ
|
ประวัติการแก้ไข 2016-01-04 09:03:31
|
|
|
|
Date :
2016-01-04 09:00:46 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
$html = '
<!DOCTYPE html>
<html>
<head>
<title>Example full width table.</title>
<style type="text/css">
.table {
border: 1px solid #ccc;
border-collapse: collapse;
width: 100%;
}
.table td,
.table th {
border: 1px solid #ccc;
}
</style>
</head>
<body>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Last name</th>
<th>Number</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sarah</td>
<td>Connor</td>
<td>002</td>
<td>Dead</td>
</tr>
<tr>
<td>John</td>
<td>Connor</td>
<td>001</td>
<td>Dead</td>
</tr>
<tr>
<td>T</td>
<td>08</td>
<td>008</td>
<td>Unknow</td>
</tr>
<tr>
<td>Sun</td>
<td>Gokou</td>
<td>005</td>
<td>WTF</td>
</tr>
</tbody>
</table>
<p>Table with 100% full width.</p>
</body>
</html>
';
include("../mpdf.php");
$mpdf=new mPDF('c','A4');
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->Output('full-width-table.pdf','I');
exit;
ผมโหลดรุ่นล่าสุด mpdf v.6.0 มาลองนะครับ รุ่นอื่นไม่ทราบมีบั๊กอะไรหรือไม่ แต่เขียนแบบเดียวกันน่าจะออกเหมือนๆกัน
จากตัวอย่างของผมเป็นแบบ 100%
|
|
|
|
|
Date :
2016-01-04 12:35:49 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ประวัติการแก้ไข 2016-01-04 12:38:55 2016-01-04 12:39:18 2016-01-04 12:39:45
|
|
|
|
Date :
2016-01-04 12:38:07 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณดูพวก css class ที่ผมกำหนดไว้ด้วยนะครับ ไม่ใช่แค่เพิ่ม table class="..."
แล้วการกำหนด WriteHtml อะไรต่างๆก็ด้วย ลองดูอย่างละเอียดทั้งหมดครับเพราะการส่งค่าต่างๆมันมีผล
คุณลองก๊อปของผมไปเทสดูก่อนว่าทำงานได้รึเปล่า ถ้าได้ก็ค่อยมาหาดูว่าอะไรที่ต่างไป
|
|
|
|
|
Date :
2016-01-04 17:00:00 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอาโค้ดล่าสุดที่แก้แล้วมาดูดีกว่าครับ
|
|
|
|
|
Date :
2016-01-04 17:07:20 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|