Overlapping of elements after multipage table in tcpdf - php

After echoing product list (usually multipage)the below content get overlapping to the first page.I have been try to solve this problem form so many no luck so for .I have seen some topic on stack over flow but doesn't work for me. Below is full working code showing above problem. How could I solve this.Full solution is greatly appreciated.
$InvAllPrct = '';
$InvAllPrct .= '<div><br>
<table border="0" cellpadding="3" style="width:100%">
<tbody>
<tr style="font-weight: bold;">
<th style="width: 6%;">Product</th>
<th style="width: 6%;">Price</th>
<th style="width: 4%;">QTY</th>
<th style="width: 7%;">Total</th>
</tr><hr>';
//----------------------get prct information-----------------------------------------------
for($i=0;$i<100;$i++){
$InvAllPrct .= '<tr>
<td style="text-align: right;">Some text</td>
<td style="text-align: right;">100</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">100</td>
</tr>';
}
$InvAllPrct .= '</tbody>
</table>
<hr style="font-weight:bold;">
</div>';
$Cname = '';
$Cname .= '<div style="float:right;">';
$Cname .= '<span style="font-weight: 600;font-style: oblique;font-size: 12px;">Some company name</span><br>';
$Cname .= '<span> some text</span><br>';
$Cname .= '</div>';
//---------------------------tax n total---------------------------------------------
$GrandTotalData = '';
$GrandTotalData .= '
<span>Sub Total: 100</span><br>';
$GrandTotalData .= '<span> tax1 : 10%</span><br>';
$GrandTotalData .= '<span> tax2 : 10%</span><br>';
$GrandTotalData .= '<span>Total : 200</span><br>';
$GrandTotalData .= '<span style=" font-weight: bold;">Grand Total : 200<hr></<span>';
// Include the main TCPDF library (search for installation path).
require('tcpdf1/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set font
$pdf->SetFont('dejavusans', '', 10);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
// add a page
$pdf->AddPage();
$pdf->MultiCell(00, 00, "Some text", 0, 'C', 0, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetFont('dejavusans', '', 7);
// create some HTML content
$y = $pdf->getY();
$pdf->writeHTMLCell('', '', '46', $y,"Some Name", 0, 0, 0, true, 'J', false);
$y = $pdf->getLastH()+$y;
$pdf->writeHTMLCell('', '', 10, $y, $InvAllPrct, 0, 0, 0, true, 'J', true);
$y = $pdf->getLastH()+$y;
// // ******Problem Starts here overlapping on above content on first page***************
$pdf->writeHTMLCell('38', '', 160, $y, $GrandTotalData, 0, 0, 0, true, 'J', true);
$html = '<div style="text-align:centre;"> Some Text......................................</div>';
$y = $pdf->getLastH()+$y;
$pdf->writeHTMLCell('', '', '', $y, $html, 0, 0, 0, true, 'J', true);
$y = $pdf->getLastH()+$y;
$html = '<div style="text-align: justify;margin: 0px 225px 17px 5px;">Some long text here.................</div><br>
<div style="text-align: justify;margin: 0px 225px 36px 5px;">Some long text here.....................</div>
';
$pdf->writeHTMLCell('144', '', '', $y, $html, 0, 0, 0, true, 'J', true);
$pdf->lastPage();
$pdf->Output('example_006.pdf', 'I');
php tcpdf

Related

FPDF error: some data has already been output. Can't send PDF file

I'm using FPDF library to generate PDF document, but I'm getting error "Some data has already been output, can't send PDF".
<?php
function fetch_data()
{
//užklausa
include('database_connection.php');
$query = "SELECT * FROM mvap.daiktas";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$id = 1;
foreach($result as $row)
{
$pavadinimas = $row['daiktoPavadinimas'];
$inventorinis = $row['inventorinisNr'];
}
$data = '2020-01-25';
$html = '
<body>
<style>
th {font-weight: bold; font-family: };
tr {font-weight: normal};
</style>
<table border="1" cellpadding="4" cellspacing="0" style="text-align: center">
<tr>
<th width="30px" height="5">Eil. Nr.</th>
<th width="130px" height="5">Materialinės vertybės pavadinimas</th>
<th width="80px" height="5">Inventorinis numeris</th>
<th width="100px" height="5">Gamyklinis numeris</th>
<th width="70" height="5">Gavimo data</th>
<th width="65" height="5">Gavėjo parašas</th>
<th width="70" height="5">Grąžinimo data</th>
<th width="80" height="5">Grąžinančio asmens parašas</th>
<th width="70" height="5">Priimančio asmens parašas</th>
<th width="80" height="5">Pastabos</th>
</tr>
<tr>
<td>'. $id .'</td>
<td>'. $pavadinimas .'</td>
<td>'. $inventorinis .'</td>
<td>-</td>
<td>'. $data .'</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</table>
</body>
';
return $html;
}
if(isset($_POST['submit1']))
{
require('libs/TCPDF/tcpdf_import.php');
$obj_pdf = new TCPDF('L', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$obj_pdf->SetCreator(PDF_CREATOR);
$obj_pdf->SetTitle("Apskaitos kortelė");
$obj_pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);
$obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$obj_pdf->SetDefaultMonospacedFont('dejavuserif');
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$obj_pdf->SetMargins(PDF_MARGIN_LEFT, '10', PDF_MARGIN_RIGHT);
$obj_pdf->setPrintHeader(false);
$obj_pdf->setPrintFooter(false);
$obj_pdf->SetAutoPageBreak(TRUE, 10);
$obj_pdf->SetFont('dejavuserif', '', 10);
$obj_pdf->AddPage();
$obj_pdf->Cell(0,6,'ĮMONĖ',0,0,'C');
$obj_pdf->Ln();
$obj_pdf->SetLineWidth(0.5);
$obj_pdf->Line(5, 15, 297-5, 15);
$obj_pdf->Ln();
$obj_pdf->SetFontSize(12);
$obj_pdf->Cell(0,20,'KOMPIUTERINĖS TECHNIKOS, RYŠIO PRIEMONIŲ IR PROGRAMINĖS ĮRANGOS APSKAITOS KORTELĖ',0,0,'C');
$obj_pdf->Ln();
$obj_pdf->SetFontSize(10);
$obj_pdf->Cell(20, 40, 'Valdybos, skyriaus pavadinimas' , 0, false, 'L', 0, '', 0, false, 'T', 'M');
$obj_pdf->Cell(230, 40, 'SKOV NKC', 0, false, 'C', 0, '', 0, false, 'T', 'M');
$obj_pdf->Line(10, 65, 297-100, 65);
$obj_pdf->Ln(0);
$obj_pdf->Cell(20, 55, 'Turto buvimo vieta, kab. Nr.' , 0, false, 'L', 0, '', 0, false, 'T', 'M');
$obj_pdf->Cell(230, 55, 'Kabinetas', 0, false, 'C', 0, '', 0, false, 'T', 'M');
$obj_pdf->Line(10, 72, 297-100, 72);
$obj_pdf->Ln(0);
$obj_pdf->Cell(20, 70, 'Atsakingo žmogaus vardas, pavardė' , 0, false, 'L', 0, '', 0, false, 'T', 'M');
$obj_pdf->Cell(230, 70, 'Vardenis Pavardenis', 0, false, 'C', 0, '', 0, false, 'T', 'M');
$obj_pdf->Line(10, 80, 297-100, 80);
$content = '';
$content .= fetch_data();
$obj_pdf->SetXY(5, 90);
$obj_pdf->writeHTML($content);
$obj_pdf->Output('doc.pdf', 'I');
}
?>
I tried to add "ob_start()" at the beggining and "ob_end_flush()" at the end. I know that it's not first topic of this problem, but tried to find information in this forum and now I have no idea what to do more. I hope somebody could help me to fix this problem.
Solved my problem. I won't delete my topic. Hope this will help for someone.
Solved problem by posting this php code to another blank php file and called that file from another file button click. Now it works without problem.

copy current tcpdf page to new tcpdf object

How to copy a certain tcpdf page to a new tcpdf object? Below is my scenario.
I have a php script which loops 50 times. Before loop I create a tcpdf object and in every loop I keep on adding new page with new page content. After the loop ends I have a pdf with 50 pages which is downloaded to the server.
Now in addition with the 50 pages pdf I also want separate pdfs of every page.
So how can I assign a page to new tcpdf object and download it?
Code
<?
include_once("_includes.php");
$db = new _database_class($GLOBALS["DB_CONNECTION_TYPE"]);
$vw = new _database_view($db);
$utl = new _utility_class($db, $vw);
$__ID = 166;
$INSTITUTE_ID = 2;
$USER_ID = 1;
$PROCESS_ID = 123;
$billingBatchInvoices = $vw->getBillingBatchInvoices($__ID);
$bankInfo = $vw->getBankInfo(1);
$bankBranchInfo = $vw->getBankBranchInfo(1);
class MYPDF extends TCPDF
{
function SetDash($black = null, $white = null)
{
if ($black !== null)
{
$s = sprintf('[%.3F %.3F] 0 d', $black * $this->k, $white * $this->k);
}
else
{
$s = '[] 0 d';
}
$this->_out($s);
}
public function Header()
{
}
public function Footer()
{
}
}
$GLOBALS["style"] = array(
'border' => 0,
'vpadding' => 'auto',
'hpadding' => 'auto',
'fgcolor' => array(0, 0, 0),
'bgcolor' => false, //array(255,255,255)
'module_width' => 1, // width of a single module in points
'module_height' => 1 // height of a single module in points
);
$pdf = new MYPDF("L", "mm", "A4", true, 'UTF-8', false);
$pdf->SetCreator('XNREL');
$pdf->SetAuthor('XNREL');
$pdf->SetTitle('Invoice');
$pdf->SetSubject('Invoice');
$pdf->SetKeywords('Invoice');
$pdf->SetAutoPageBreak(true, 0);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setLanguageArray($l);
$pdf->setPrintHeader(true);
$pdf->setPrintFooter(true);
//header and footer information
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$COPY[1] = "Bank Copy";
$COPY[2] = "School's Copy";
$COPY[3] = "Parent's Copy";
$result = $vw->getLookupValue("PS_QUEUED", "PROCESS_STATUS", $INSTITUTE_ID);
$status = $result['LOOKUP_VALUE_ID'];
$bindArray = array(
":PROCESS_ID" => $PROCESS_ID,
":INSTITUTE_ID" => $INSTITUTE_ID,
":COLUMN_VALUE" => $__ID,
":COLUMN_REF" => "BILLING_ID",
":TABLE_REF" => "BILLING",
":PROCESS_STATUS" => $status,
":CREATED_BY" => $USER_ID
);
$query = "SELECT PROCESS_ID FROM SYS_PROCESS_LOG WHERE PROCESS_ID=:PROCESS_ID AND INSTITUTE_ID=:INSTITUTE_ID AND COLUMN_VALUE=:COLUMN_VALUE AND COLUMN_REF=:COLUMN_REF AND TABLE_REF=:TABLE_REF AND PROCESS_STATUS=:PROCESS_STATUS AND CREATED_BY=:CREATED_BY";
$found = $db->fetchRS($query, $bindArray);
$bindArray = array(
":INSTITUTE_ID" => $INSTITUTE_ID
);
$query = "SELECT DATE_FORMAT FROM CAS_INSTITUTE WHERE INSTITUTE_ID=:INSTITUTE_ID";
$result = $db->fetchRecord($query, $bindArray);
$lookup = $vw->getLookupValueInfo($result['DATE_FORMAT']);
$S_USER_DATE_FORMAT = $lookup['LOOKUP_VALUE_CODE'];
$result = $vw->getLookupValue("PS_IN_PROGRESS", "PROCESS_STATUS", $INSTITUTE_ID);
$status = $result['LOOKUP_VALUE_ID'];
$bindArray = array(
":PROCESS_ID" => $PROCESS_ID,
":INSTITUTE_ID" => $INSTITUTE_ID,
":COLUMN_VALUE" => $__ID,
":COLUMN_REF" => "BILLING_ID",
":TABLE_REF" => "BILLING",
":PROCESS_STATUS" => $status,
":STARTED_AT" => date("Y-m-d H:i:s")
);
$query = "UPDATE SYS_PROCESS_LOG SET PROCESS_STATUS=:PROCESS_STATUS, STARTED_AT=TO_DATE(:STARTED_AT,'G_DATEFORMAT_3') WHERE PROCESS_ID=:PROCESS_ID AND INSTITUTE_ID=:INSTITUTE_ID AND COLUMN_VALUE=:COLUMN_VALUE AND COLUMN_REF=:COLUMN_REF AND TABLE_REF=:TABLE_REF";
$db->executeQuery($query, $bindArray);
$looper=1;
foreach ($billingBatchInvoices as $billingBatchInvoice)
{
$invoiceInfo = $vw->getInvoiceInfo($billingBatchInvoice['CUSTOMER_BILLING_ID']);
$invoiceItems = $vw->getInvoiceItems($billingBatchInvoice['CUSTOMER_BILLING_ID']);
$pdf->AddPage('L');
$GLOBALS["C_X"] = 5;
for ($i = 1; $i <= 3; $i++)
{
$GLOBALS["C_Y"] = 10;
$fontSize = 35;
$pdf->Image('../resources/common/img/logo/logo.png', $GLOBALS["C_X"] + 6.5, $GLOBALS["C_Y"] + 0.5, 15);
$html = '<table style="border:1px solid black; font-size:' . $fontSize . 'px; font:Helvetica,Arial,sans-serif;" border="1" cellpadding="5">';
$html = $html . '<tr>
<td width="95" style="text-align:center"></td>
<td width="205" height="40" style="text-align:center">' .
$bankInfo['INSTITUTE_DESC']
. '</td>
</tr>
</table>';
$pdf->writeHTMLCell($w = 0, $h = 0, $GLOBALS["C_X"], $GLOBALS["C_Y"], $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
$fontSize = 30;
$GLOBALS["C_Y"] = $pdf->GetY() + 1;
$html = '<table bgcolor="#000000" style="border:1px solid black; font-size:' . $fontSize . 'px; font:Helvetica,Arial,sans-serif; color:#FFFFFF; " border="1" cellpadding="5">';
$html = $html . '
<tr>
<td width="300" style="text-align:center">' . $COPY[$i] . '</td>
</tr>
</table>';
$pdf->writeHTMLCell($w = 0, $h = 0, $GLOBALS["C_X"], $GLOBALS["C_Y"], $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
$GLOBALS["C_Y"] = $pdf->GetY() + 1;
// $GLOBALS["C_Y"] = $pdf->GetY();
// $pdf->Image('../resources/common/img/Silkbank.jpg', $GLOBALS["C_X"] + 1, $GLOBALS["C_Y"] + 1, 85.5);
$fontSize = 25;
// $GLOBALS["C_Y"] = $pdf->GetY() + 10.5;
$html = '<table style="border:1px solid black; font-size:' . $fontSize . 'px; font:Helvetica,Arial,sans-serif;" border="1" cellpadding="5">';
$html = $html . '
<tr>
<td width="300" style="text-align:left">Bank: ' . $bankInfo['BANK_DESC'] . '</td>
</tr>
<tr>
<td width="300" style="text-align:left">Branch: ' . $bankBranchInfo['BRANCH_DESC'] . '</td>
</tr>
<tr>
<td width="300" style="text-align:left">A/C Title: ' . $bankBranchInfo['ACCOUNT_TITLE'] . '</td>
</tr>
<tr>
<td width="300" style="text-align:left">A/C No.: ' . $bankBranchInfo['ACCOUNT_NO'] . '</td>
</tr>
</table>';
$pdf->writeHTMLCell($w = 0, $h = 0, $GLOBALS["C_X"], $GLOBALS["C_Y"], $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
$GLOBALS["C_Y"] = $pdf->GetY() + 2;
$html = '<table style="border:1px solid black; font-size:' . $fontSize . 'px; font:Helvetica,Arial,sans-serif;" border="1" cellpadding="5">';
$html = $html . '
<tr>
<td width="95" style=""><strong>Invoice #</strong></td>
<td width="205" style=""><strong>' . $invoiceInfo['INVOICE_NO'] . '</strong></td>
</tr>
<tr>
<td width="95" style=""><strong>Name</strong></td>
<td width="205" style="">' . $invoiceInfo['PERSON_FIRST_NAME'] . ' ' . $invoiceInfo['PERSON_LAST_NAME'] . ' - ' . $invoiceInfo['PIN'] . '</td>
</tr>
<tr>
<td width="95" style=""><strong>Class / Campus</strong></td>
<td width="205" style="">' . $invoiceInfo['CLASS_DESC'] . ' - ' . $invoiceInfo['CAMPUS_DESC'] . '</td>
</tr>
<tr>
<td width="95" style=""><strong>Issue Date</strong></td>
<td width="205" style="">' . $utl->convertDBDateToUserDate($invoiceInfo['BILL_DATE'], $S_USER_DATE_FORMAT) . '</td>
</tr>
<tr>
<td width="95" style=""><strong>Due Date</strong></td>
<td width="205" style="">' . $utl->convertDBDateToUserDate($invoiceInfo['DUE_DATE'], $S_USER_DATE_FORMAT) . '</td>
</tr>
</table>';
$pdf->writeHTMLCell($w = 0, $h = 0, $GLOBALS["C_X"], $GLOBALS["C_Y"], $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
$GLOBALS["C_Y"] = $pdf->GetY() + 2;
$html = '<table style="border:1px solid black; font-size:' . $fontSize . 'px; font:Helvetica,Arial,sans-serif;" border="1" cellpadding="5">';
$html = $html . '
<tr bgcolor="#CCCCCC";>
<td width="25" style="text-align:center"><strong>No</strong></td>
<td width="185" style=""><strong>Processing Fee</strong></td>
<td width="90" style="text-align:right"><strong>Amount</strong></td>
</tr>';
$C = 1;
foreach ($invoiceItems as $ROW)
{
$html = $html . '
<tr>
<td width="25" style="text-align:center">' . $C . '</td>
<td width="185" style="">' . $ROW['ITEM'] . '</td>
<td width="90" style="text-align:right">' . number_format($ROW['ITEM_AMOUNT']) . '/-</td>
</tr>';
$C++;
}
$html = $html . '
<tr>
<td width="210" colspan="1" style="text-align:right"><strong>Total (Rs.)</strong></td>
<td width="90" style="text-align:right"><strong>' . number_format($invoiceInfo['AMOUNT']) . '/-</strong></td>
</tr>
<tr>
<td colspan="2" width="300" colspan="1"><strong>Total Amount in Words:</strong> ' . ucwords(strtolower($utl->converNumberToWords($invoiceInfo['AMOUNT']))) . ' Only</td>
</tr>';
$html = $html . '</table>';
$pdf->writeHTMLCell($w = 0, $h = 0, $GLOBALS["C_X"], $GLOBALS["C_Y"], $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
$GLOBALS["C_Y"] = $pdf->GetY() + 2;
$html = '<table style="border:1px solid black; font-size:' . $fontSize . 'px; font:Helvetica,Arial,sans-serif;" border="1" cellpadding="5">';
$html = $html . '<tr>
<td width="300" style="">
<strong>Payment Terms:</strong>
</td>
</tr>
<tr>
<td width="300" style="">
1. Deposit fee between 9:00-4:30pm Mon-Fri.
</td>
</tr>
<tr>
<td width="300" style="">
2. Deposit payment within 10 days of due date.
</td>
</tr>
<tr>
<td width="300" style="">
<small>This is a computer generated document and does not require signature</small>
</td>
</tr>
</table>';
$pdf->writeHTMLCell($w = 0, $h = 0, $GLOBALS["C_X"], $GLOBALS["C_Y"], $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);
$GLOBALS["C_X"] = $GLOBALS["C_X"] + 100;
if ($i <> 3)
{
$pdf->SetDash(2, 2);
$pdf->Line($GLOBALS["C_X"] - 6, 0, $GLOBALS["C_X"] - 6, 250);
}
}
$pdfnew = new MYPDF("L", "mm", "A4", true, 'UTF-8', false);
$pdfnew->AddPage('L');
$pdf->copyPage($pdf->getPage($looper));
$pdfnew->Output($invoiceInfo['PIN'] . "-Invoice-Voucher.pdf", "F");
$looper++;
}
$result = $vw->getLookupValue("PS_SUCCESS", "PROCESS_STATUS", $INSTITUTE_ID);
$status = $result['LOOKUP_VALUE_ID'];
$bindArray = array(
":PROCESS_ID" => $PROCESS_ID,
":INSTITUTE_ID" => $INSTITUTE_ID,
":COLUMN_VALUE" => $__ID,
":COLUMN_REF" => "BILLING_ID",
":TABLE_REF" => "BILLING",
":PROCESS_STATUS" => $status,
":ENDED_AT" => date("Y-m-d H:i:s")
);
$query = "UPDATE SYS_PROCESS_LOG SET PROCESS_STATUS=:PROCESS_STATUS, ENDED_AT=TO_DATE(:ENDED_AT,'G_DATEFORMAT_3') WHERE PROCESS_ID=:PROCESS_ID AND INSTITUTE_ID=:INSTITUTE_ID AND COLUMN_VALUE=:COLUMN_VALUE AND COLUMN_REF=:COLUMN_REF AND TABLE_REF=:TABLE_REF";
$db->executeQuery($query, $bindArray);
$pdf->Output("Batch-Invoice-Voucher.pdf", "F");
?>
Create another object INSIDE the loop, add the page to that.
Possibly you want these in an array too, so you could define $separatePages = []; before the loop, and create the single page inside the loop, and add it to the array, so you have it after the looping is complete.
$pdf = new MYPDF("L", "mm", "A4", true, 'UTF-8', false);
$pagesArray = [];
// existing code
foreach ($billingBatchInvoices as $billingBatchInvoice) {
// existing code
// create new pdf
$page = new MYPDF("L", "mm", "A4", true, 'UTF-8', false);
// add to page the same way as you did main pdf
$pagesArray[] = $page;
}

How to add a div with image and text 180 degree rotate in tcpdf

I have searched a lot for this solution but no luck, as tcpdf have a poor documentation so i found nothing, what i need is a name plate print as pdf using tcpdf, ant the template is so simple just as the image is
But the problem is i can not rotate the top section properly. here is my code
$obj_pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$obj_pdf->AddPage('L' , 'A5');
$obj_pdf->StartTransform();
$obj_pdf->Rotate(-180);
$obj_pdf->image($logo1, 165 , 65, 0, 90, "PNG", "" , "M", true);
$obj_pdf->image($logo2, 0 , 65, 0, 90, "PNG", "" , "R", true);
$name = $functional_user->first_name .' '. $functional_user->last_name ;
$obj_pdf->SetTopMargin(-120);
$obj_pdf->SetLeftMargin(10);
$obj_pdf->setCellPaddings(0,0,0,0);
$tbl = '<br> <div class= "rotate" style="transform: rotate(180deg);">
<table cellpadding="2" >
<tr>
<td><h1 style = "font-size: 40px; line-height: 1.3">'.$name.' </h1>
<br><br><span style="font-size: 13px">
'.$org_logo_text.' </span>
</td>
</tr>
</table>
</div>';
$obj_pdf->writeHTML($tbl, true, false, false, false, '');
$obj_pdf->StopTransform();
$obj_pdf->SetTopMargin(78);
$obj_pdf->image($logo1, 10 , 70, 40, 20, "PNG", "" , "M", true);
$obj_pdf->image($logo2, 165 , 70, 40, 20, "PNG", "" , "R", true);
$name = $functional_user->first_name .' '. $functional_user->last_name ;
$obj_pdf->SetTopMargin(100);
$obj_pdf->SetLeftMargin(10);
$obj_pdf->setCellPaddings(0,0,0,0);
$tbl = '<br>
<table cellpadding="2" >
<tr>
<td><h1 style = "font-size: 40px; line-height: 1.3">'.$name.' </h1>
<br><br><span style="font-size: 13px">
'.$org_logo_text.' </span>
</td>
</tr>
</table>';
$obj_pdf->writeHTML($tbl, true, false, false, false, '');
$obj_pdf->lastPage();
$obj_pdf->Output('/tmp/Nameplate_' . $i . '.pdf', 'F');
$obj_pdf->Close();
Can somebody help me with this ??
Well I solved this my own, what i did wrong is using rotate($angle) function. And it does actually rotate the section but it take the center point as (0,0) or left-top corner And so that after rotate the whole section places outside of the pdf page. So finally i use rotate($angle, $px, $py) function where px and py will push that section from corresponding axis and places the required place . Here is my code
$obj_pdf->StartTransform();
$angle= 180;
$px= 105;
$py= 36;
$obj_pdf->Rotate($angle, $px, $py);
$obj_pdf->image($company_logo, 10 , 0, 40, 20, "PNG", "" , "M", true);
$obj_pdf->image($organization_logo, 165 , 0, 40, 20, "PNG", "" , "R", true);
$name = $functional_user->first_name .' '. $functional_user->last_name ;
$obj_pdf->SetTopMargin(27);
$obj_pdf->SetLeftMargin(10);
$fz = "35px";
if( strlen( $name )> 20) $fz = "40px";
else if( strlen($name)> 18 ) $fz = "33px";
$tbl = '<br><table cellpadding="1" >
<tr>
<td><h1 style = "font-size: '.$fz.'; line-height: 1.3">'.$name.' </h1>
<br><br><span style="font-size: 13px">
'.$org_logo_text.' </span>
</td>
</tr>
</table>';
$obj_pdf->writeHTML($tbl, true, false, false, false, '');
$obj_pdf->StopTransform();

TCPDF when It creates more than one page it does not print the next pages correctly

My output of my PDF page when it prints more than one page it does not print correctly. Please look at the example
Here is an example of the PDF file expenses.pdf.
If you notice where the page starts printing on page 2 it overwrites itself.
Also it does not cut off the page on the first page above the category so it carry's the info onto the 2nd page.
Also there are only 19 items in this list yet it prints 5 pages and repeats the items.
class PDF extends tcpdf
{
// Page header
function Header()
{
$this->SetFont('Times', 'BI', 20, '', 'false');
// Move to the right
$this->Ln(5);
$this->Cell(60);
$this->Cell($w, $h=0, $txt='EXPENCE REPORT', $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0,
$ignore_min_height=false, $calign='T', $valign='M');
$this->Line (0, 13, 210, 13, $style=array());
// Line break
$this->Ln(5);
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
$pdf = new PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage ($orientation='', $format='', $keepmargins=false, $tocpage=false);
$pdf->SetAutoPageBreak ($auto, $margin=16);
$pdf->SetPrintHeader(true);
$pdf->SetPrintFooter(true);
$pdf->setFontSubsetting(true);
// set margins
$pdf->SetMargins(10, PDF_MARGIN_TOP, 10);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->SetFont('helvetica', '', 14, '', true);
$tbl_header = '<table cellspacing="3" style="width: 100%; text-align: center; font-size: 8pt;">';
$tbl_footer = '</table>';
$tbl = '';
$sql = "SELECT `expensetype`.`typeid`, `expensetype`.`exptype`, `expenses`.`expid`,`expenses`.`expdate`, `expenses`.`checktype`, `expenses`.`payee`,`expenses`.`details`, `expenses`.`amount` FROM `expensetype` INNER JOIN `expenses` ON
`expensetype`.`typeid` = `expenses`.`typeid`WHERE (`expenses`.`pid` = " . $pid . ")";
$result = $db->query($sql);
$expensetype = null;
foreach($result as $expense) {
if($expensetype != $expense['typeid']) {
$exptype = $expense['exptype'];
$tbl .= '
<tr>
<td height="10" style="width: 100%;"></td>
</tr>
<tr style="background-color:#E1E0E0">
<td height="20" style="width: 25%; text-align: left">Category:</td>
<td height="20" style="width: 75%; text-align: left">'.$exptype.'</td>
</tr>';
$tbl .= '
<tr style="background-color:#CEC7C7">
<th style="width: 20%">Date:</th>
<th style="width: 30%">Payee:</th>
<th style="width: 30%">Detalls:</th>
<th style="width: 20%">Amount:</th>
</tr>';
$pdf->SetXY(2, 20);
$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, '');
}
$expdate=phpdate($expense['expdate']);
$tbl .= '
<tr>
<td style="width: 20%; text-align: center">'.$expdate.'</td>
<td style="width: 30%; text-align: center">'.$expense['payee'].'</td>
<td style="width: 30%; text-align: center">'.$expense['details'].'</td>
<td style="width: 20%; text-align: center">'.$expense['amount'].'</td>
</tr>';
if($expensetype != $expense['typeid']) {
$expensetype = $expense['typeid'];
}
}
$pdf->SetXY(2, 20);
$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, '');
// $tbl .= '
//<tr>
//<th style="width: 85%; text-align: right;">Total Amount:' .$totalamount.' </th>
//</tr>';
ob_end_clean();
$pdf->Output();
This is what the script looks like now
$sql = "SELECT `expensetype`.`typeid`, `expensetype`.`exptype`, `expenses`.`expid`,`expenses`.`expdate`, `expenses`.`checktype`, `expenses`.`payee`,`expenses`.`details`, `expenses`.`amount` FROM `expensetype` INNER JOIN `expenses` ON
`expensetype`.`typeid` = `expenses`.`typeid`WHERE (`expenses`.`pid` = " . $pid . ")";
$result = $db->query($sql);
$expensetype = null;
foreach($result as $expense) {
$tbl = '';
if($expensetype != $expense['typeid']) {
$exptype = $expense['exptype'];
$tbl .= '
<tr>
<td height="10" style="width: 100%;"></td>
</tr>
<tr style="background-color:#E1E0E0">
<td height="20" style="width: 25%; text-align: left">Category:</td>
<td height="20" style="width: 75%; text-align: left">'.$exptype.'</td>
</tr>';
$tbl .= '
<tr style="background-color:#CEC7C7">
<th style="width: 20%">Date:</th>
<th style="width: 30%">Payee:</th>
<th style="width: 30%">Detalls:</th>
<th style="width: 20%">Amount:</th>
</tr>';
$pdf->SetXY(2, 20 + $pdf->GetY());
$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, '');
}
$expdate=phpdate($expense['expdate']);
$tbl = '';
$tbl .= '
<tr>
<td style="width: 20%; text-align: center">'.$expdate.'</td>
<td style="width: 30%; text-align: center">'.$expense['payee'].'</td>
<td style="width: 30%; text-align: center">'.$expense['details'].'</td>
<td style="width: 20%; text-align: center">'.$expense['amount'].'</td>
</tr>';
$pdf->SetXY(2, 20 + $pdf->GetY());
$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, '');
if($expensetype != $expense['typeid']) {
$expensetype = $expense['typeid'];
}
}
$pdf->Output();
Main cause is that you don't reinitialize the variable $tbl, that holds the body of your table every loop.
foreach($result as $expense) {
$tbl = '';
should make your output more in the line that you want.
Now you've got solved the problem of
Also there are only 19 items in this list yet it prints 5 pages and
repeats the items.
The overwriting occurs because you position your output absolut on the page with:
$pdf->SetXY(2, 20);
That's ok for the first time. Your next content (next loop) has to consider the actual Y position. You can get this with the `GetY()' method.
$pdf->SetXY(2, 20 + $pdf->GetY());
should take care of that.

Php Shopping cart - Size and length for each quantity of a type of product

I have been working on an online store. Project's aim is to add products to a shopping cart.. Customer should be able to change size & length for each quantity for a product.
Example :
I sell a Product named A
customer order 5 pieces of product A
So he should be able to set 5 size and lengths for product A as the quantity is 5.
Then TCPDF is also there to email the created invoice.
I just want some help with the setting of sizes and length for each quantity. Please Please help..
ALso if its possible please assist me with adding those lengths and sizes to the pdf created which is under function sendmail
Following is the code i have written till now...
<?php
include("include/session.php");
require_once('config/lang/eng.php');
require_once('tcpdf.php');
//Start the session
session_start();
//Create 'cart' if it doesn't already exist
if (!isset($_SESSION['SHOPPING_CART'])){ $_SESSION['SHOPPING_CART'] = array(); }
//Add an item only if we have the threee required pices of information: name, price, qty
if (isset($_GET['add']) && isset($_GET['price'])
&& isset($_GET['qty']) && isset($_GET['size'])
&& isset($_GET['length'])&& isset($_GET['code']) ){
//Adding an Item
//Store it in a Array
$ITEM = array(
//Item name
'name' => $_GET['add'],
//Item Price
'price' => $_GET['price'],
//Qty wanted of item
'qty' => $_GET['qty'],
'size' => $_GET['size'],
'length' => $_GET['length'],
'code' => $_GET['code']
);
//Add this item to the shopping cart
$_SESSION['SHOPPING_CART'][] = $ITEM;
//Clear the URL variables
header('Location: ' . $_SERVER['PHP_SELF']);
}
//Allowing the modification of individual items no longer keeps this a simple shopping cart.
//We only support emptying and removing
else if (isset($_GET['remove'])){
//Remove the item from the cart
unset($_SESSION['SHOPPING_CART'][$_GET['remove']]);
//Re-organize the cart
//array_unshift ($_SESSION['SHOPPING_CART'], array_shift ($_SESSION['SHOPPING_CART']));
//Clear the URL variables
header('Location: ' . $_SERVER['PHP_SELF']);
}
else if (isset($_GET['empty'])){
//Clear Cart by destroying all the data in the session
session_destroy();
//Clear the URL variables
header('Location: ' . $_SERVER['PHP_SELF']);
}
else if (isset($_POST['update'])) {
//Updates Qty for all items
foreach ($_POST['items_qty'] as $itemID => $qty) {
//If the Qty is "0" remove it from the cart
if ($qty == 0) {
//Remove it from the cart
unset($_SESSION['SHOPPING_CART'][$itemID]);
}
else if($qty >= 1) {
//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['qty'] = $qty;
}
foreach ($_POST['items_size'] as $itemID => $size) {
//If the Qty is "0" remove it from the cart
if($size >= 1) {
//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['size'] = $size;
}
}
foreach ($_POST['items_length'] as $itemID => $length) {
//If the Qty is "0" remove it from the cart
//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['length'] = $length;
}
}
//Clear the POST variables
header('Location: ' . $_SERVER['PHP_SELF']);
}
$req_user = $session->username;
$req_user_info = $database->getUserInfo($req_user);
$need= $req_user;
/* Username */
$username=$req_user;
$q = "SELECT name, address, city, country, postal, email, number, account, counter "
."FROM ".TBL_USERS." WHERE username = '$username'";
$result = $database->query($q);
$num_rows = mysql_numrows($result);
for($i=0; $i<$num_rows; $i++){
$storename = mysql_result($result,$i,"name");
$address = mysql_result($result,$i,"address");
$city = mysql_result($result,$i,"city");
$country = mysql_result($result,$i,"country");
$postal = mysql_result($result,$i,"postal");
$email = mysql_result($result,$i,"email");
$number = mysql_result($result,$i,"number");
$account = mysql_result($result,$i,"account");
$counter = mysql_result($result,$i,"counter");
}
?>
function sendmail($storename,$address,$city,$country,$postal,$number, $email, $account, $counter){
class MYP extends TCPDF {
// Load table data from file
public function LoadData($file) {
// Read file lines
$lines = file($file);
$data = array();
foreach($lines as $line) {
$data[] = explode(';', chop($line));
}
return $data;
}
// Colored table
public function ColoredTable($header, $account, $counter) {
// Colors, line width and bold font
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetDrawColor(0, 0, 0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');
// Header
$w = array(35, 40);
$num_headers = count($header);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
$ref = $account.$counter;
$today = date("m.d.y");
$this->Cell($w[0], 6, $today, 'LR', 0, 'C', $fill);
$this->Cell($w[1], 6, $ref, 'LR', 0, 'C', $fill);
$this->Ln();
$fill=!$fill;
$this->Cell(array_sum($w), 0, '', 'T');
}
public function ColoredTable2($header) {
// Colors, line width and bold font
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetDrawColor(0, 0, 0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');
// Header
$w = array(30, 40, 20,20,20,20);
$num_headers = count($header);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
$totalamount=0;
foreach ($_SESSION['SHOPPING_CART'] as $itemNumber => $item) {
$tot=$item['qty'] * $item['price'];
$this->Cell($w[0], 6, $item['name'], 'LR', 0, 'C', $fill);
$this->Cell($w[1], 6, $item['size'], 'LR', 0, 'C', $fill);
$this->Cell($w[2], 6, $item['qty'], 'LR', 0, 'C', $fill);
$this->Cell($w[3], 6, $item['length'], 'LR', 0, 'C', $fill);
$this->Cell($w[4], 6, $item['price'], 'LR', 0, 'C', $fill);
$this->Cell($w[5], 6, $tot, 'LR', 0, 'C', $fill);
$this->Ln();
$totalamount=$totalamount+$tot;
$fill=!$fill;
}
$this->Cell(array_sum($w), 0, '', 'T');
}
public function ColoredTable1($header,$txt2,$txt3,$txt4,$txt5) {
// Colors, line width and bold font
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetDrawColor(0, 0, 0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');
// Header
$w = array(70);
$num_headers = count($header);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
$this->Cell($w[0], 6, $txt2, 'LR', 0, 'L', $fill);
$this->Ln();
$this->Cell($w[0], 6, $txt3, 'LR', 0, 'L', $fill);
$this->Ln();
$this->Cell($w[0], 6, $txt4, 'LR', 0, 'L', $fill);
$this->Ln();
$this->Cell($w[0], 6, $txt5, 'LR', 0, 'L', $fill);
$this->Ln();
$fill=!$fill;
$this->Cell(array_sum($w), 0, '', 'T');
}
}
function curPageName2() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
$url= curPageName2();
$len=strlen($url);
$furl=substr($url,0,($len-4));
$furl1=$furl.';1;2;3;4;5;6'."\n";
$fp = fopen('cache/table_data_demo1.txt', 'w');
fwrite($fp, $furl1);
fclose($fp);
// create new PDF document
$pdf = new MYP(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example INVOICE');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
//Print all the items in the shopping cart
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' INVOICE', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('times', '', 10);
// add a page
$pdf->AddPage();
// set color for background
$pdf->SetFillColor(255, 255, 127);
// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0)
// set some text for example
$txt = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
$header = array('Tax Date', 'Invoice No.');
$html = <<<EOD
<p>Suite-10<br/>3-11 Imperial Road<br/>London<br/>Greater London SW6 2AG<br/><br/></p>
EOD;
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);
$pdf->ColoredTable($header, $account, $counter);
$html = <<<EOD
<br />
EOD;
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$html = <<<EOD
<br />
EOD;
// Print text using writeHTMLCell()
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$txt2=$storename;
$txt3=$address;
$txt4=$city.",".$country.",".$postal;
$txt5=$number;
$header=array('Invoice To');
$pdf->ColoredTable1($header,$txt2,$txt3,$txt4,$txt5);
$html = <<<EOD
<br />
EOD;
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$html = <<<EOD
<br />
EOD;
$totamt = 0;
foreach ($_SESSION['SHOPPING_CART'] as $itemNumber => $item) {
$item['name'];
$item['price'];
$item['qty'];
$tot=$item['qty'] * $item['price'];
$item['size'];
$item['length'];
$totamt=$totamt+$tot;
}
// Print text using writeHTMLCell()
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$header = array('Item', 'Size', 'Quantity','Length','Rate','Amount');
;
$data = $pdf->LoadData('cache/table_data_demo1.txt');
$pdf->ColoredTable2($header);
$html = <<<EOD
<br />
EOD;
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$pdf->Ln(4);
// set color for background
$pdf->SetFillColor(220, 255, 220);
$vat=(($totamt*20)/100);
$final=$totamt+$vat;
$vat1=' RATE VAT NET ';
$vat2='E#20% '.$vat.' '.$totamt;
$vat3='Terms of Payment: Invoice to be paid immediately. All goods remain the property of Intuzuri UK Ltd until full payment has been received. Copyright in the designs listed above remain the property of Intuzuri UK Ltd. Intuzuri UK Ltd Registered in England Company No. 07880714. Company VAT Number : GB 134 9206 21';
if(strtolower($country) == "usa" || strtolower($country) =="united states of america" || strtolower($country) == "america")
{
$tot1='SUBTOTAL : '.'$'.$totamt;
$tot2='VAT Total : '.'$'.$vat;
$tot5='TOTAL : '.'$'.$final;
$tot3='Payments/Credits : $0.00';
$tot4='Balance Due : '.'$'.$final;
}
else
{
$tot1='SUBTOTAL : '.'GBP '.$totamt;
$tot2='VAT Total : '."GBP ".$vat;
$tot5='TOTAL : '."GBP ".$final;
$tot3="Payments/Credits : GBP 0.00";
$tot4='Balance Due : '."GBP ".$final;
}
$pdf->MultiCell(105, 50, $vat1."\n".$vat2."\n\n".$vat3, 1, 'C', 0, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->MultiCell(65, 50,"\n\n".$tot1."\n\n".$tot2."\n\n".$tot3."\n\n".$tot4."\n\n".$tot5, 1, 'C', 0, 0, '', '', true, 0, false, true, 40, 'M');
// move pointer to last page
$pdf->lastPage();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_005.pdf', 'F');
$date = $_POST["datepick"];
$info = $_POST["TextArea1"];
$fileatt = "example_005.pdf"; // Path to the file
$fileatt_type = "application/pdf"; // File Type
$fileatt_name = "Sales_Confirmation.pdf"; // Filename that will be used for the file as the attachment
$email_from = ""; // Who the email is from
$email_subject = "Sales Confirmation"; // The Subject of the email
$email_message = " ";
$email_message .= "Retailer ".$storename.", has just placed an order. The Order Form is there in the attachment.<br>"
."Please Note Below are the additional details requested by the retailer. <br>"
."Expected Delivery Date : ".$date.".<br>"
."Additional Information : ".$info.".<br>"
."If you would like to Contact the seller, you can contact here : ".$email;
$email_to = ""; // Who the email is to
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($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}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";
$sent = #mail($email_to, $email_subject, $email_message, $headers);
}
if (isset($_POST['submit']))
{
$counter++;
$field = "counter";
$value= $counter;
$database->updatecounter($username,$field,$value );
//Everything is good, proceed
sendmail($storename,$address,$city,$country,$postal,$number, $email, $account, $counter);
$result_message = "Thank You, You order have been successfully placed, You will recieve an email shortly., ";
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Intuzuri Retail Online Order Form</title>
<script type="text/javascript" src="datepickr.js"></script>
<style type="text/css">
.calendar {
font-family: 'Trebuchet MS', Tahoma, Verdana, Arial, sans-serif;
font-size: 0.9em;
background-color: #EEE;
color: #333;
border: 1px solid #DDD;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
padding: 0.2em;
width: 14em;
}
.calendar a {
outline: none;
}
.calendar .months {
background-color: #F6AF3A;
border: 1px solid #E78F08;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
color: #FFF;
padding: 0.2em;
text-align: center;
}
.calendar .prev-month,
.calendar .next-month {
padding: 0;
}
.calendar .prev-month {
float: left;
}
.calendar .next-month {
float: right;
}
.calendar .current-month {
margin: 0 auto;
}
.calendar .months a {
color: #FFF;
text-decoration: none;
padding: 0 0.4em;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
}
.calendar .months a:hover {
background-color: #FDF5CE;
color: #C77405;
}
.calendar table {
border-collapse: collapse;
padding: 0;
font-size: 0.8em;
width: 100%;
}
.calendar th {
text-align: center;
}
.calendar td {
text-align: right;
padding: 1px;
width: 14.3%;
}
.calendar td a {
display: block;
color: #1C94C4;
background-color: #F6F6F6;
border: 1px solid #CCC;
text-decoration: none;
padding: 0.2em;
}
.calendar td a:hover {
color: #C77405;
background-color: #FDF5CE;
border: 1px solid #FBCB09;
}
.calendar td.today a {
background-color: #FFF0A5;
border: 1px solid #FED22F;
color: #363636;
}
</style>
<style type="text/css">
<!--
#formArea #orderForm #formColumns {
width:800px;
margin:auto;
}
#formArea #orderForm #formColumns #leftColumn {
float:left;
width:400px;
}
#orderForm {
height:500px;
}
#formArea #orderForm #formColumns #rightColumn {
float:right;
width:400px;
}
#formArea #orderForm #formColumns th {
text-align: left;
}
.copyright {
font-size: 9pt;
}
-->
</style>
</head>
<?
/**
* User has already logged in, so display relavent links, including
* a link to the admin center if the user is an administrator.
*/
if($session->logged_in){
?>
<body>
<div align="center">
<?
echo "<b>$session->username</b>, you are logged in. <br><br>"
."[My Account] "
."[Edit Account] "
."[Logout] "
."[View Other Products]";
?>
</div>
<div id="pageHeader">
<h1 align="center">View Your Order here</h1>
</div>
<div id="shoppingCartDisplay">
<form action="" method="post" name="shoppingcart">
<?php
//We want to include the shopping cart in the email
ob_start();
?>
<table align="center" width="800" border="1">
<tr align="center">
<th scope="col"> </th>
<th scope="col">Item Name</th>
<td scope="col">Unit Price ( <?php if(strtolower($country) == "usa" || strtolower($country) =="united states of america" || strtolower($country) == "america")
{
echo "$";
}
else
{
echo '£';
}
?> )</td>
<th scope="col">Qty</th>
<td scope="col">Cost ( <?php if(strtolower($country) == "usa" || strtolower($country) =="united states of america" || strtolower($country) == "america")
{
echo "$";
}
else
{
echo "£";
}
?> )</td>
<th scope="col">Change Size</th>
<th scope="col">Change Length</th>
</tr>
<?php
//Print all the items in the shopping cart
foreach ($_SESSION['SHOPPING_CART'] as $itemNumber => $item) {
?>
<tr align="center" id="item<?php echo $itemNumber; ?>">
<td>remove</td>
<td><?php echo $item['name']; ?></td>
<td><?php echo $item['price']; ?></td>
<td><input name="items_qty[<?php echo $itemNumber; ?>]" type="text" id="item<?php echo $itemNumber; ?>_qty" value="<?php echo $item['qty']; ?>" size="2" maxlength="3" /></td>
<td><?php echo $item['qty'] * $item['price']; ?></td>
<td><select name="items_size[<?php echo $itemNumber; ?>]" value="<?php echo $item['size']; ?>" type="text" id="item<?php echo $itemNumber; ?>_size" >
<option selected="selected" value="<?php echo $item['size']; ?>"><?php echo $item['size']; ?></option>
<option value="2">2</option>
<option value="4">4</option>
<option value="6">6</option>
<option value="8">8</option>
<option value="10">10</option>
<option value="12">12</option>
<option value="14">14</option>
<option value="16">16</option>
<option value="18">18</option>
<option value="20">20</option>
<option value="22">22</option>
<option value="24">24</option>
<option value="26">26</option>
<option value="28">28</option>
<option value="30">30</option>
</select>
<?php
$order=strtotime("now");
if($cntry == "USA" || $cntry =="United States Of America" || $cntry == "America")
{
$price=100;
}
else
{
$price=200;
}
?>
<td><select name="items_length[<?php echo $itemNumber; ?>]" type="text" select="<?php echo $item['length']; ?>" id="item<?php echo $itemNumber; ?>_length" >
<option selected="selected" value="<?php echo $item['length']; ?>"><?php echo $item['length']; ?></option>
<option value="46">46</option>
<option value="48">48</option>
<option value="50">50</option>
</select>
</tr>
<?php
}
?>
</table>
<?php $_SESSION['SHOPPING_CART_HTML'] = ob_get_flush(); ?>
<p>
<div align="center">
Please Make all you selections first (Quantity, Size, Length) and then update.<br /><br /><input type="submit" name="update" id="update" value="Update Cart" /> Keep Shopping
</div>
</p>
</form>
</div>
<div id="formArea">
<?php if (isset($result_message)) {?>
<div align="center"><h3><?php echo $result_message; ?></h3></div>
<?
}
else {
?>
<p align="center">Once selected all your dresses, please submit your order after reviewing your account details.</p>
<div id="orderForm">
<form action="" method="post" name="orderform">
<div id="formColumns">
<div id="leftColumn">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<p align="center"><b>Your Account Information</b></p>
<tr height="21">
<td height="21"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Store Name </b></font></td>
<td height="21"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $storename; ?></font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Email Address </b></font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $email; ?>
</font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Phone Number </b></font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $number; ?>
</font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Billing Address</b></font></td>
<td><? echo $address.',&nbsp<br>'
."$city, $country, $postal"; ?>
</td>
</tr>
<tr>
<td>
</tr>
<tr>
</tr>
</table>
</div>
<div id="rightColumn">
<table width="100%" height="50%" border="0" cellpadding="3" cellspacing="0">
<p align="center"><b>Additional Information</b></p>
<tr>
<td align="left">
<div align="left">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Expected Delivery Date: </font></div> </td>
<td>
<input required="required" id="datepick" name="datepick" class="date-pick" />
<script type="text/javascript">
new datepickr('datepick', { dateFormat: 'm-d-Y' });
</script>
</td>
</tr>
<tr>
<td>
<div align="left">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Additional Details: </font></div> </td>
<td>
<textarea id="TextArea1" name="TextArea1" cols="20" rows="8"></textarea>
</td>
</tr>
<tr>
<td>
<div align="left">
<input name="submit" type="submit" id="submit" value="Submit"></div> </td>
<td style="color: red;">
*Before submitting please verify that all details are correct.
</td>
</tr>
<tr>
<td>
<div align="left"> </div> </td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<?php } ?>
</div>
<?
}
else
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=main.php">';
}
?>
</body>
</html>
I tried to do it by creating another session but cant seem to get it done myself.
I wanted to make it like... when you will change the quantity to 5... so there should appear 5 dropdowns for size and 5 for length. I could make the dropdowns but couldnt store the selected value in the session.
Any help is appreciated.
To help this explain, Theres a session named Shopping Cart. Now that has array items like price size quantity etc. Now there a function :-
else if (isset($_POST['update'])) {
//Updates Qty for all items
foreach ($_POST['items_qty'] as $itemID => $qty) {
//If the Qty is "0" remove it from the cart
if ($qty == 0) {
//Remove it from the cart
unset($_SESSION['SHOPPING_CART'][$itemID]);
}
else if($qty >= 1) {
//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['qty'] = $qty;
}
foreach ($_POST['items_size'] as $itemID => $size) {
//If the Qty is "0" remove it from the cart
if($size >= 1) {
//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['size'] = $size;
}
}
foreach ($_POST['items_length'] as $itemID => $length) {
//If the Qty is "0" remove it from the cart
//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['length'] = $length;
}
}
Here its updating the size and length for each product. I want it for each quantity. For ex if you select 5 quantity customer should be able to select 5 sizes and 5 lengths current can only chose 1 each no matter how big the quantity is.. Maybe this will help you understand
First of all, you need to store items in session via their id, not via their name or automatically generated index. If name changes, you won't find them in your database. You want to use that id directly in $_SESSION['SHOPPING_CART'][ 'item_id' ] = array(), since that will allow you to quickly find the item and work with it.
Since you have multiple entities of the same item, you need to use more complex array to store them. Simple solution could be as follows:
$ITEM = array(
'name' => $_GET['add'],
'qty' => $_GET['qty'],
'price' => $_GET['price'] * $_GET['qty'],
'size' => array_fill(0, $_GET['qty'], $_GET['size']),
'length' => array_fill(0, $_GET['qty'], $_GET['length']),
'code' => $_GET['code']
);
$_SESSION['SHOPPING_CART'][ $_GET['item_id'] ] = $ITEM;
When user wants to change the data, you create dropdown for every row in size and length arrays and then save them accordingly.
I would, however, suggest storing this data in database with some sort of user_id. In current design, if user closes his browser accidentally or simply comes back when session will expire, his whole order will be lost.
Edit: working with sizes and lengths.
foreach ($_SESSION['SHOPPING_CART'] as $item_id => $item)
{
echo '<p>Name: ' . $item['name'] . ' for ' . $item['price'] . '$</p>';
foreach($item['size'] as $j => $size)
{
echo '<p>#' . $j . ': size ' . $size . ', length ' . $item['length'][$j] . '</p>';
}
}
Replace echo with inputs for editing and put them into a form.

Categories