PHP+html webpage to pdf - php
I am stuck with this thing and don't know what to do.I have googled so many times, and got to know about fpdf,html2pdf,tcpdf.
I am creating an invoice,in which i have used html and php code.I want to display that data in pdf want to convert the whole page to pdf and also print and save it.But I don't know what to do.I am new to this and don't know much.
Have tried some code but I am only getting the html text as output also want php data to.
this is the webpage for invoice.
Code:
index.php
<?php
if(!isset($_POST['submit']))
{
?>
<form method="post" action=''>
<div id="page-wrap">
<textarea id="header" name="text" disabled="disabled">INVOICE</textarea>
<div id="identity">
<textarea name="address" id="address" disabled="disabled" style="background-color:#FFF;color:#000">Address</textarea>
<div id="logo">
<img id="image" src="images/logo.png" alt="logo" /></div>
</div>
<div style="clear:both"></div>
<div id="customer">
<!-- <textarea id="customer-title" disabled="disabled" style="background-color:#FFF;color:#000">Widget Corp.
c/o Steve Widget</textarea>
-->
<table id="meta">
<tr>
<td class="meta-head">Invoice #</td>
<td><textarea>000123</textarea></td>
</tr>
<tr>
<td class="meta-head">Date</td>
<td><textarea id="date"></textarea></td>
</tr>
</table>
</div>
<table id="items">
<tr>
<th>Item</th>
<th>Unit Cost</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<?php
include("./config.php");
$q=0;$u=0;$t=0;$tt=0;$s=0;$v=0;
$sql="SELECT m.order_id,m.table_id,l.item_id,l.order_quantity,i.item_name,i.item_price from order_m m,order_list l,item_list i where m.order_id=l.order_id and l.item_id=i.item_id and table_id=2";
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result))
{
$q=$q+$row[3];
$u=$u+$row[5];
$t=$t+($row[3]*$row[5]);
?>
<tr class="item-row">
<td class="item-name"><?php echo $row[4]?></td>
<td><?php echo $row[5];?></td>
<td><?php echo $row[3];?></td>
<td><?php echo $row[3]*$row[5];}?></td>
</tr>
<tr>
<td>Total </td>
<td><?php echo $u; ?></td>
<td><?php echo $q;?></td>
<td><?php echo $t;?></td>
</tr>
<?php
$sql1="Select * from tax";
$res=mysqli_query($con,$sql1);
$row1=mysqli_fetch_row($res);
if($row1[0]!=0)
{
$v=($row1[0]*$t)/100;
?>
<tr>
<td> </td>
<td></td>
<td>VAT%</td>
<td><?php echo $row1[0]."%";?></td>
</tr>
<?php
}
else
{
}
if($row1[1]!=0)
{
$s=($row1[1]*$t)/100;
?>
<tr>
<td> </td>
<td></td>
<td>Service Tax.%</td>
<td><?php echo $row1[1]."%";?></td>
</tr>
<?php
}
else
{
}
?>
<tr>
<td></td>
<td></td>
<td>Total</td>
<td><?php $tt=$t+$v+$s; echo round($tt);?></td>
</tr>
</table>
<div id="terms">
<h5>Terms</h5>
<textarea>NET 30 Days. Finance Charge of 1.5% will be made on unpaid balances after 30 days.</textarea>
</div>
</div>
<input type="submit" name="submit" value="Print" />
</form>
<?php
}
else
{
ob_start();
require("html2pdf.php");
$the_file = "./index.php";
$myfile = fopen($the_file, "r") or die("Unable to open file!!!!<br><br><br>");
$homepage = file_get_contents($the_file);
fclose($myfile);
$pdf = new PDF_HTML();
$pdf->AddPage();
$pdf->SetFont('Arial','B',9);
$pdf->WriteHTML($homepage);
$pdf->Output();
ob_end_flush();
exit;
}
?>
Here is the output of the conversion.
you can use tcpdf to render pdf from html. it provides more flexibility
https://tcpdf.org/examples/
see this code, this will generate dummy invoice.
<?php
function generateInvoice(){
$invoice_no = 0001;
require_once('tcpdf/tcpdf.php');
class MYPDF extends TCPDF
{
public function Header() {
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 12);
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// 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(0, 0, 0);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(True, 0);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (#file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
//set custom font
//$fontname = TCPDF_FONTS::addTTFfont('OpenSans-Semibold.ttf', 'TrueTypeUnicode', '',12);
// use the font
$pdf->SetFont($fontname, '', 12, '', false);
// add a page
$pdf->AddPage();
$pdf->setFontSize(40);
$pdf->Write(0, 'Company', '', 0, 'C', true, 0, false, false, 0);
$pdf->setFontSize(12);
$y = $pdf->getY();
$pdf->writeHTMLCell(100, 90, '18', $y+10, '<table cellspacing="0" style="background:#000;" cellpadding="1">
<tr>
<td align="left" columnspan="1" style="font-size:15px" width="80" > Name</td>
<td align="left" style="font-size:15px" width="">name surname</td>
</tr>
<tr>
<td align="left" columnspan="1" style="font-size:15px" width="80" > Address</td>
<td align="left" style="font-size:15px" width="">India</td>
</tr>
<tr>
<td align="left" columnspan="1" style="font-size:15px" width="80" > Mob.</td>
<td align="left" style="font-size:15px" width="">0000000</td>
</tr>
<tr>
<td align="left" columnspan="1" style="font-size:15px" width="80" > Email</td>
<td align="left" style="font-size:15px" width="">johnday#johnday.johnday</td>
</tr>
</table>', 0, 0, 0, false, 'J', true);
$y = $pdf->getY();
$pdf->writeHTMLCell(100, 30, 114, $y, '<table cellspacing="0" style="background:#000;" cellpadding="1">
<tr>
<td align="left" columnspan="1" style="font-size:15px" width="100" > Invoice # :</td>
<td align="left" style="font-size:15px" width="">1000</td>
</tr>
<tr>
<td align="left" columnspan="1" style="font-size:15px" width="100" > Invoice Date</td>
<td align="left" style="font-size:15px" width="">22/02/2016</td>
</tr>
</table>', 0, 0, 0, false, 'J', true);
$y = $pdf->getY();
//$pdf->writeHTMLCell('',10,'',$y+5,$html, 0, 1, 0, true, 'C', true);
$pdf->writeHTML($html, true, false, false, false, '');
$y = $pdf->getY();
$data ='<table cellspacing="0" style="background:#000;" border="1" cellpadding="2">
<thead>
<tr style="background-color:#f2f2f2;">
<th align="center" columnspan="1" style="font-size:15px" width="140" > item</th>
<th align="center" columnspan="1" style="font-size:15px" width="140" > price</th>
<th align="center" columnspan="1" style="font-size:15px" width="140" > quantity</th>
<th align="center" columnspan="1" style="font-size:15px" width="140" > subtotal</th>
<th align="center" columnspan="1" style="font-size:15px" width="140" > total</th>
</tr>
</thead>
<tbody>
<tr style="background-color:#fff;">
<td align="center" columnspan="1" style="font-size:15px" width="140" >book</td>
<td align="center" columnspan="1" style="font-size:15px" width="140" >2</td>
<td align="center" columnspan="1" style="font-size:15px" width="140" >2</td>
<td align="center" columnspan="1" style="font-size:15px" width="140" >4</td>
<td align="center" columnspan="1" style="font-size:15px" width="140" >4</td>
</tr>
<tr><td></td>
<td></td>
<td></td>
<td align="left" columnspan="1" style="font-size:15px" width="140" > Subtotal</td>
<td align="left" style="font-size:13px" width="140">$'. number_format((float) (121), 2, '.', '').'</td>
</tr>
<tr style="background-color:#f2f2f2;">
<td></td>
<td></td>
<td></td>
<td align="left" columnspan="1" style="font-size:15px" width="140" > GST</td>
<td align="left" style="font-size:13px" width="140">included</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td align="left" style="font-size:15px" columnspan="1" width="140"> Discount</td>
<td align="left" style="font-size:13px" width="140">$'.number_format((float) (12121.212), 2, '.', '') .'</td>
</tr>
<tr style="background-color:#f2f2f2;">
<td></td>
<td></td>
<td></td>
<td align="left" style="font-size:15px" columnspan="1" width="140" > Amount Paid</td>
<td align="left" style="font-size:13px" width="140">$'.number_format((float) (1212), 2, '.', '').'</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td align="left" style="font-size:15px" columnspan="1" width="140" > Amount Due</td>
<td align="left" style="font-size:13px" width="140">$'.number_format((float) (1221), 2, '.', '').'</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>';
//$pdf->writeHTMLCell('', '','',$y+8,$data, 0, 1, 0, true, 'C', true);
$pdf->writeHTML($data, true, false, false, false, '');
$y = $pdf->getY();
$pdf->writeHTMLCell('', '', '4',$y+4, '<table cellspacing="0" style="background:#000;" cellpadding="2">
<tr style="background-color:#21B67B;">
<td align="center" style="font-size:20px;color:#fff;" columnspan="0" width="390">PAYMENT METHODS WE ACCEPT</td>
</tr>
<tr>
<td align="left" style="font-size:15px;" width="440">We accept payment by cash, credit card or bank deposit<br></td>
</tr>
<tr>
<td align="left" style="font-size:15px;" width="400">Our Bank Details: </td>
</tr>
<tr>
<td align="left" style="font-size:15px;" width="400">Bank name: demo Bank </td>
</tr><tr>
<td align="left" style="font-size:15px;" width="400">BSB Number: 000000 </td>
</tr><tr>
<td align="left" style="font-size:15px;" width="400">Account Number: 00000 </td>
</tr>
<tr>
<td align="left" style="font-size:15px;" width="400">Account Name: demo demo Ltd </td>
</tr>
<tr>
<td align="left" style="font-size:15px;" width="400"></td>
</tr>
<tr>
<td align="left" style="font-size:15px;" width="400">To make a payment via credit card please call our office on (000) 0000 0000. Cash can be paid on delivery.</td>
</tr>
<tr>
<td align="left" style="font-size:15px;" width="400"></td>
</tr>
<tr>
<td align="center" style="font-size:24px;color:#21B67B;" width="400">Thank you for your business!</td>
</tr>
</table><br<br>', 0, 0, 0, false, 'J', true);
$pdf->lastPage();
$pdf->Output($invoice_no.'.pdf', 'I');
return $invoice_no.'.pdf';
}
generateInvoice();
?>
Related
how to automatically add a second page in mpdf?
I want to convert html file into pdf using mpdf class. working well but the count > 30 the page rotating no display , <?php include("connection.php"); $phase=mysql_query("select * from session where status=1"); $phasee = mysql_fetch_array($phase); $mindate = $phasee['st_date']; $maxdate = $phasee['end_date']; $query_omr = mysql_query("SELECT * from sit_details a,staff_details b where b.staff_code=a.staff_code and a.val_center=".$_GET['num']); $staffrowdet = mysql_fetch_array($query_omr); $query_exam_session = mysql_query("SELECT * from exam_session"); $row_exam_session = mysql_fetch_array($query_exam_session); $randm=rand(100001,999999); $text_page=' <style> table { width:1000px; font-family:Times New Roman, Times; border-collapse: collapse; text-align:justify; padding:2px; font-size:12px; text-transform: uppercase; } td, th { height:30px; text-transform: uppercase; padding:2px; } </style> <table id="simple-table" > <tr><td colspan="2"> <table> <tr> <td rowspan="3"><img src="assets/images/logo.gif" width="80px" /></td> <td align="center" style="font-size:20px"><strong>Heading1 </strong></td> </tr> <tr> <td align="center" style="font-size:16px"><strong>Heading2 - '. $row_exam_session['session'].' </strong> </td> </tr> <tr> <td align="center" style="font-size:14px"><strong>DETAIL</strong></td> </tr> </table> </td></tr> <tr><td colspan="2"> <table id="dynamic-table" class="table table-striped table-bordered table-hover" width="900" align="left"> <tr> <th colspan="6" style="font-size:14px" align="left">PERIOD : FROM <u>'.$mindate .' </u> TO <u>'.$maxdate.' </u> </th> </tr> <div style="width:50px;height:50px;border:1px solid #000;"></div> </table> </td></tr> <tr> <td> <strong><caption> Form Details</caption> </strong> <table id="dynamic-table" class="table table-striped table-bordered table-hover" border="1" style="page-break-inside: avoid"> <tr bgcolor="#CCCCCC" > <th align="center" width="50px"><label class="control-label bolder blue">Sl.No </label></th> <th align="center" width="100px"><label class="control-label bolder blue">Staff ID </label></th> <th align="left" width="100px"><label class="control-label bolder blue"> Staff Name</label></th> <th align="left" width="100px"><label class="control-label bolder blue"> Designation </label></th> </tr>'; $c1=0; while($row_dummy = mysql_fetch_array($query_omr)) { $text_page=$text_page.' <tr> <td align="center"><h3>'. $c1 .'</h3></td> <td align="center"><h3>'. $row_dummy['staff_code'].'</h3></td> <td align="left"><h3>'. $row_dummy['staff_name'].'</h3></td> <td align="left"><h3>'. $row_dummy['staff_designation'].'</h3></td> </tr>'; $c1++; } $text_page=$text_page.' <tr> <table > </tr> </table> </table> </td> </tr> <table id="dynamic-table" class="table table-striped table-bordered table-hover" border="1" width="800" > <tbody> <tr> <th align="center" width="300px" ></th> <br/> <th align="center" width="150px">Post Held</th> <th align="center" width="250px">Name</th> <th align="center" width="50px">Signature</th> </tr> <tr> <td> </td> <td align="center" height="70"><strong> <br/> Officer / <br/> Coordinator </strong> </td> <td height="70"></td> </tr> <tbody> <td align="right" width="300px" valign="bottom" rowspan="2" > </td> </table> </table> <table> <tr><td align="left"><h4>'.$randm.'</h4></td><td align="right"><h4>'.date('d-m-Y H:i:s').'</h4></td></tr> </table> '; //echo $text_page; //exit; ob_end_clean(); ini_set('memory_limit', '500000M'); include("MPDF57/mpdf.php"); //$mpdf = new mPDF('c', 'A4-L','0', '0', '10', '10','10', '10'); $mpdf = new mPDF( '', // mode - default '' 'A4', // format - A4, for example, default '' 0, // font size - default 0 '', // default font family 10, // margin_left 10, // margin right 5, // margin top 0, // margin bottom 5, // margin header 5, // margin footer 'P' // L - landscape, P - portrait ); $mpdf->autoPageBreak = true; $mpdf->AddPage(); $fname=$_GET['num'].".pdf"; $mpdf->SetWatermarkImage('assets/images/logo.jpg'); $mpdf->setFooter('{PAGENO}'); $mpdf->showWatermarkImage = true; $mpdf->WriteHTML($text_page); $mpdf->Output($fname, 'D'); exit; ?> the pdf downloaded, but the count<30 if the rowcount>30 the page not responding. how to solve this error. i cannot find out the solution. kindly suggest any other mpdf sample program which is matching my requirement.
HTML CSS PHP, Table design
i have a problem to create table like this image in website, can anyone help me to solve that?. blue line in picture. i just don't know how to create table like this image. especially reference no, it has custom border line. Here is table design you can check my code here too MY CODE this is my code <html xmlns="http://www.w3.org/1999/ifxhtml"> <head profile="http://www.w3.org/2005/10/profile"> <title>Glisten - A free web template</title> </head> <body> <table width="800" border="1" align="center"> <tbody> <tr> <td colspan="2" align="center" bgcolor=""><table width="800" border="1" align="center"> <tbody> <tr> <td width="125">Reference No</td> <td colspan="4"> </td> <td colspan="2" bgcolor="#8B8A8A" align="center"></td> </tr> <tr> <td align="center" bgcolor="#FF0004"><strong>NG TINEM</strong></td> </tr> <tr> <td>Site ID</td> <td colspan="3" align="center"></td> <td width="185">BSC Name</td> <td colspan="2" align="center"></td> </tr> <tr> <td>Site Name</td> <td colspan="3" align="center"></td> <td>New Site ID</td> <td colspan="2" align="center"></td> </tr> <tr> <td>Sales Cluster</td> <td colspan="3" align="center"></td> <td>LAC</td> <td colspan="2" align="center"></td> </tr> <tr> <td>Ne Type</td> <td colspan="3" align="center"></td> <td>Config</td> <td colspan="2" align="center"></td> </tr> <tr> <td>Band</td> <td colspan="3" align="center"></td> <td>PO Number</td> <td colspan="2" align="center"></td> </tr> <tr> <td>Cell ID</td> <td width="80" align="center"></td> <td width="82" align="center"></td> <td width="80" align="center"></td> <td> </td> <td colspan="2"> </td> </tr> <tr> <td colspan="7" > </td> </tr> <tr> <td align="center">Integration Date</td> <td align="center"></td> <td align="center">On Air Date</td> <td align="center"></td> <td align="center">Acceptance Date</td> <td colspan="2" align="center"></td> </tr> <tr> </tbody> </table> </body></html>
First identify the total columns to be created. Then use attribute of table like "colspan" to span the columns.
Add following style to your table (I have added class table in your second table tag): <style type="text/css"> .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th { padding: 8px; line-height: 1.42857143; vertical-align: top; } table { border-collapse: collapse; border-spacing: 0; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; } </style> <table width="800" align="center"> <tbody> <tr> <td colspan="2" align="center" bgcolor=""><table class="table" width="800" border="1" align="center"> <tbody> <?php while($data = mysql_fetch_array($query)){ if($data['dt_report']=='Yes'){ $check_dt_report='checked="checked"'; } else{ $check_dt_report=''; }if($data['kpi_stats']=='Yes'){ $check_kpi_stats='checked="checked"'; } else{ $check_kpi_stats=''; } if($data['clear_alarm']=='Yes'){ $check_clear_alarm='checked="checked"'; } else{ $check_clear_alarm=''; } if($data['configuration']=='Yes'){ $check_configuration='checked="checked"'; } else{ $check_configuration=''; } if($data['neighbor']=='Yes'){ $check_neighbor='checked="checked"'; } else{ $check_neighbor=''; } ?> <tr> <td width="125">Reference No</td> <td colspan="4"> </td> <td colspan="2" bgcolor="#8B8A8A" align="center"><?php echo $data['no_ref']; ?></td> </tr> <tr> <td align="center" bgcolor="#FF0004"><strong>NG TINEM</strong></td> </tr> <tr> <td>Site ID</td> <td colspan="3" align="center"><?php echo $data['site_id']; ?></td> <td width="185">BSC Name</td> <td colspan="2" align="center"><?php echo $data['bsc_name']; ?></td> </tr> <tr> <td>Site Name</td> <td colspan="3" align="center"><?php echo $data['site_name']; ?></td> <td>New Site ID</td> <td colspan="2" align="center"><?php echo $data['new_site_id']; ?></td> </tr> <tr> <td>Sales Cluster</td> <td colspan="3" align="center"><?php echo $data['sales_cluster']; ?></td> <td>LAC</td> <td colspan="2" align="center"><?php echo $data['lac']; ?></td> </tr> <tr> <td>Ne Type</td> <td colspan="3" align="center"><?php echo $data['ne_type']; ?></td> <td>Config</td> <td colspan="2" align="center"><?php echo $data['config']; ?></td> </tr> <tr> <td>Band</td> <td colspan="3" align="center"><?php echo $data['band']; ?></td> <td>PO Number</td> <td colspan="2" align="center"><?php echo $data['po_number']; ?></td> </tr> <tr> <td>Cell ID</td> <td width="80" align="center"><?php echo $data['cell_id1']; ?></td> <td width="82" align="center"><?php echo $data['cell_id2']; ?></td> <td width="80" align="center"><?php echo $data['cell_id3']; ?></td> <td> </td> <td colspan="2"> </td> </tr> <tr> <td colspan="7" > </td> </tr> </tbody> </table>
php while loop table repeating fix
I have following do while loop be it keep on repeating the table for each record how to fix it? full table repeat for each record. Also for every row fetch can I add <table width="1510" border="1" align="center" cellpadding="2" cellspacing="2" class="table table-bordered" > <tbody> <form name="f1"> <? $counter = 1; $total_marks = 0; $total_obtain = 0; while($row_rsDept = mysql_fetch_array($rsDept)) { if($counter === 1) { ?> <tr> <th width="71" rowspan="3" align="center" valign="middle" scope="col"><h4>Sr. No</h4></th> <th width="229" align="right" valign="top" scope="col"> </th> <th colspan="8" align="center" valign="middle" scope="col"><h3>Detail of Marks</h3></th> </tr> <tr> <th rowspan="2" align="left" scope="row"><h4>Subject</h4></th> <td colspan="2" align="center"><h4>Thoery</h4></td> <td colspan="2" align="center"><h4>Practical</h4></td> <td width="134" rowspan="2" align="center" valign="middle"><h4>Marks Obtain</h4></td> <td width="144" rowspan="2" align="center" valign="middle"><h4>Max Marks</h4></td> <td width="137" rowspan="2" align="center" valign="middle"><h4>Remarks</h4></td> <td width="137" rowspan="2" align="center" valign="middle"><h4>Grace Marks</h4></td> </tr> <tr> <td width="134">Obtained Marks</td> <td width="144">Total Marks</td> <td width="143">Obtained Marks</td> <td width="153">Total Marks</td> </tr> <? } ?> <tr> <th align="left" scope="row"> </th> <th align="left" scope="row"><?php echo $row_rsDept['SUBJECTS']; ?></th> <td><?php echo $row_rsDept['THEORYOBTAINEDMARKS']; ?></td> <td><?php echo $row_rsDept['THEORYTOTALMARKS']; ?></td> <td><?php echo $row_rsDept['PRACTICALOBATINEDMARKS']; ?></td> <td><?php echo $row_rsDept['PRACTICALTOTALMARKS']; ?></td> <td align="center" valign="middle"><?php echo $row_rsDept['MARKSOBTAINED']; ?></td> <td align="center" valign="middle"><?php echo $row_rsDept['MAXMARKS']; ?></td> <td align="center" valign="middle"><span class="style8"><?php echo $row_rsDept['REMARKS']; ?></span></td> <td align="center" valign="middle"><?php echo $row_rsDept['GRACEMARKS']; ?></td> </tr> <tr> <th colspan="6" align="right" valign="middle" scope="row"><h4>Total</h4></th> <td align="center" valign="middle"><span class="style8"><?php echo $row_rsDept['TOTALMARKS']; ?></span></td> <td align="center" valign="middle">=total of above ( )</td> <td align="center" valign="middle"> </td> <td align="center" valign="middle"> </td> </tr> <?php } ?> <tr> <th colspan="10" align="left" valign="middle" scope="row"> </th> </tr> <tr> <th colspan="8" align="left" valign="middle" scope="row"> </th> <th align="left" valign="middle" scope="row"> </th> <th align="left" valign="middle" scope="row"> </th> </tr> <tr> <th colspan="8" align="left" valign="middle" scope="row"><br></th> <th align="left" valign="middle" scope="row"> </th> <th align="left" valign="middle" scope="row"> </th> </tr> </form> </table> I tried to fix but not working for me
Inside loop you need to increment counter variable Inside loop add this line $counter++;
Creating PDF with TCPDF shows Undefined index: cols in tcpdf/tcpdf.php on line 16928
I wanted to use TCPDF to generate a PDF report. but every time it shows me error on line 16928 and I can't understand what to do... It would be great if you could help me here is my code: <?php $html = " <html> <head> <link rel='stylesheet' href='form.css'> </head> <body> <div class='header'> <h4>وزارت بهداشت، درمان و آموزش کشور</h4> <h4>Ministry of Health & Medical Education</h4> <table> <tr> <td class='engterm'>University of medical science:</td><td class='val'>[SAMPLE_ECHO]</td><td class='perterm'>دانشگاه علوم پزشکی:</td> </tr> <tr> <td class='engterm'>Medical center:</td><td class='val'>[SAMPLE_ECHO]</td><td class='perterm'>مرکز پزشکی آموزشی درمانی:</td> </tr> </table> </div> <div class='body'> <table class='main' border='1'> <tr> <td class='main' colspan='1' rowspan='2' style='text-align: left;'> <table style='margin: 0 auto;'> <tr> <td class='engterm'>Clinic no.:</td><td class='val'>[sample]</td><td class='perterm'>شماره درمانگاهی:</td> </tr> </table> </td> <td class='main' colspan='2' rowspan='2' style='text-align: center; width: 50%'> <h4>برگ خلاصه پرونده</h4> <h4>Unit Summery Sheet</h4> </td> <td class='main' colspan='1' rowspan='2' style='direction: ltr;'> <table style='margin: 0 auto;'> <tr> <td class='engterm'>Unit no.:</td><td class='val'>[sample]</td><td class='perterm'>شماره پرونده:</td> </tr> </table> </td> </tr> <tr></tr> <tr> <td class='main' rowspan='1'> <table class='data'> <td>Attending Physician:</td><td>SampleData</td><td>پزشک معالج:</td> </table> </td> <td class='main' rowspan='2'> <table class='data'> <tr><td>Ward:</td><td>Sample</td><td>بخش:</td></tr> <tr><td>Room:</td><td>Sample</td><td>اتاق:</td></tr> <tr><td>Bed:</td><td>Sample</td><td>تخت:</td></tr> </table> </td> <td class='main' rowspan='1'> <table class='data'> <td>Name:</td><td>Sample</td><td>نام:</td> </table> </td> <td class='main' rowspan='1'> <table class='data'> <td>Family name:</td><td>Sample</td><td>نام خانوادگی:</td> </table> </td> </tr> <tr> <td class='main'> <table class='data'> <td>Admission date:</td><td>Sample</td><td>تاریخ پذیرش:</td> </table> </td> <td class='main'> <table class='data'> <td>Date of Birth:</td><td>Sample</td><td>تاریخ تولد:</td> </table> </td> <td class='main'> <table class='data'> <td>Father's name:</td><td>Sample</td><td>نام پدر:</td> </table> </td> </tr> <tr> <td class='main'> <table class='data'> <td></td><td>Sample</td><td>تاریخ ترخیص:</td> </table> </td> <td class='main'> <table class='data'> <td>Occupation:</td><td>Sample</td><td>شغل:</td> </table> </td> <td class='main'> <table class='data'> <td>Marriage status:</td> <td> <input type='radio' name='marriage_status' value='married'>متاهل / Married<br> <input type='radio' name='marriage_status' value='single'>مجرد / Single </td> <td>وضعیت تاهل:</td> </table> </td> <td class='main'> <table class='data'> <td>Sex:</td> <td> <input type='radio' name='sex' value='male'>مرد / Male<br> <input type='radio' name='sex' value='female'> زن / Female </td> <td>جنسیت:</td> </table> </td> </tr> <tr> <td colspan='4'> <table class='data'> <td colspan='1' style='text-align: left;'>Address:</td><td colspan='2'>Sample</td><td colspan='1' style='text-align: right;'>آدرس:</td> </table> </td> </tr> <tr> <td colspan='4'> <table class='data'> <td colspan='1'>Final Diagnosis:</td> <td colspan='2'>Sample</td> <td colspan='1'>تشخصی نهایی:</td> </table> </td> </tr> <tr> <td colspan='4'> <table class='data'> <td colspan='1'>Medical & Surgical Procedures:</td> <td colspan='2'>Sample</td> <td colspan='1'>اقدامات درمانی و اعمال جراحی:</td> </table> </td> </tr> <tr> <td colspan='4'> <table class='data'> <td colspan='1'>Results of Paraclinical Examination:</td> <td colspan='2'>Sample</td> <td colspan='1'>پاراكلينيكي آزمايشات نتايج:</td> </table> </td> </tr> <tr> <td colspan='4'> <table class='data'> <td colspan='1'>Disease Progress (Cause of Death):</td> <td colspan='2'>Sample</td> <td colspan='1'>سیر بیماری (درصورت فوت، علت مرگ):</td> </table> </td> </tr> <tr> <td colspan='4'> <table class='data'> <td colspan='1'>Patient's Condition on Discharge:</td> <td colspan='2'>Sample</td> <td colspan='1'>وضعیت بیمار هنگام ترخیض:</td> </table> </td> </tr> <tr> <td colspan='4'> <table class='data'> <td colspan='1'>Recommendations after discharge:</td> <td colspan='2'>Sample</td> <td colspan='1'>توصیههای پس از ترخیض:</td> </table> </td> </tr> <tr> <td colspan='4'> <table class='data'> <td colspan='1'>Attending Physician's Name & Signature:</td> <td colspan='2'>Sample</td> <td colspan='1'>نام و امضا پزشک معالج:</td> </table> </td> </tr> </table> </div> </body> </html>"; require_once('tcpdf/tcpdf.php'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); if (#file_exists(dirname(__FILE__).'/lang/eng.php')) { require_once(dirname(__FILE__).'/lang/eng.php'); $pdf->setLanguageArray($l); } $pdf->SetFont('helvetica', '', 9); $pdf->AddPage(); $pdf->writeHTML($html, true, 0, true, 0); $pdf->lastPage(); $pdf->Output('htmlout.pdf', 'I'); ?> When reading the page from web server, it shows me the following error: Notice: Undefined index: cols in /home/aien/public_html/Arash.Sammak/JSON Return/tcpdf/tcpdf.php on line 16928
You have to add a valid <thead> element to every table. TCPDF parses the <thead> element to determine the number of columns in a table when it outputs tables in PDF. Also, check your HTML twice is valid or not if some other errors keep occurring. Hope this helps.
Php HTML DOM parsing
<table width="100%" cellspacing="0" cellpadding="0" border="0" id="Table4"> <tbody> <tr> <td valign="top" class="tx-strong-dgrey"> <a class="anc-noul" href="http://www.example.com/catalog/proddetail.asp?logon=&langid=EN&sku_id=0665000FS10129471&catid=25653"> Apple 8GB 3rd Generation iPod Touch</a></td> </tr> <tr> <td valign="top" class="element-spacer"/> </tr> <tr> <td valign="top" class="tx-normal-grey"> Product detail <a href="http://www.example.com/catalog/proddetail.asp?logon=&langid=EN&sku_id=0665000FS10129471&catid=25653"> More Info</a></td> </tr> <tr> <td valign="top" class="element-spacer"/> </tr> <tr> <td valign="top" class="tx-normal-red"> <span class="tx-strong-dgrey">Price:</span> $189.99</td> </tr> <tr> <td valign="top">You save: $9.00 after instant savings</td> </tr> <tr> <td valign="top" class="element-spacer"/> </tr> <tr> <td valign="top" class="tx-normal-grey"> <a href="http://www.example.com/catalog/subclass.asp?catid=25653&logon=&langid=EN"> View similar products</a> <a href="http://www.example.com/catalog/mfr.asp?man=Apple&catid=19&logon=&langid=EN"> View similar products with same brand</a> </td></tr> <tr> <td valign="top" class="element-spacer"/> </tr> </tbody> </table> I want to be able to get the $189.99. echo $ret[0]->find('tr', 4)->plaintext; This outputs: 'Price: $189.99' I just need $189.99, not 'Price:'
$exp = explode(":", $ret[0]->find('tr', 4)->plaintext); $price =$exp[1];