Convert HTML table into a text file without losing format - php

I am unable to find any post which has answer to my issue.
I have html file which has a table, need to convert this to a text file without losing the format USING php script, as it has to be printed as is on a dotmatrix printer.
OR if there is any other way of doing this, pl suggest !
The table is a Invoice format, pl see below:
<table width='100' height='300' border='0' cellspacing='0' cellpadding='1'> <tr> <td><img src='spacer.jpg' width='100' height='1'></td> <td><table width='840' border='1' cellspacing='2' cellpadding='0'><tr><td width='660' colspan='2' valign='top'><br><br><br><br><br><br><br><br><br>Customer Name: 3M India Ltd<br>
Address:Plat 48-51 Electronic City<br><br></td><td width='180' valign='top'><br><br><br><br><br><br><br><br><br>
Inv No: 78788<br><br>Date: 20/04/2012 12:28:18<br><br>
</td> </tr> <tr> <td width='292' valign='top'>DC Nos: 500, <br><br></td><td valign='top'> Your Order No.: 322<br>
C.E.Reg No.: <br>
Vehicle No.: KA-01-N-2345<br><td valign='top'> Party:<br>
TIN: 29400127541<br>
CST: 29400127541<br></td> </tr> <tr> <td colspan='2'>Sl No. Description Tariff Code Rate Qty </td> <td>Amount</td> </tr> <tr> <td colspan='3'> <table width='840' height='160' border='0' cellspacing='1' cellpadding='0'> <tr valign='top'> <td width='87'>1</td> <td width='247'>Argon</td> <td width='165'>AR1223</td> <td width='92'>120</td> <td width='67'>1 Nos</td> <td width='182'>120.00</td> </tr> </table> </td> </tr> <tr> <td colspan='2' valign='top'><div align='right'><br>VAT: 5.00 %<br>Demurrage: <br> Freight: <br><br> </div>Rupees Four Hundred & Fourty One Only.</td><td valign='top'><br> 21.00<br> 0.00<br> 300.00<br><br> </td> </tr> <tr> <td colspan='2' valign='top'><div align='right'>Total:<br><br>Rounded Off</div></td> <td valign='top'>441.00<br><br>441.00<br><br></td> </tr></table> </td> </tr></table>

Could you not open the HTML file in something like Microsoft Word and then send it to print?
You could also convert the HTML file to PDF, there's several free ones (Google "html to pdf conversion") as another option to see if it works.

Related

fpdf html table text break into cell not work

i'm using fpdf library with html table class that give me the possibility to write table with table tr and td
how is possible to write two value into same cell of html table? i tryed with br and \n but not work.
this is my code
$html = "
<table border='1'>
<tr>
<td width='240' height='90'>$detail[name] $detail[vase] $detail[quality]</td>
<td width='70' height='90'>$logistic_date</td>
<td width='70' height='90'>$detail[lot]</td>
<td width='60' height='90'>$warehouse</td>
<td width='220' height='90'>$detail[note]</td>
<td width='50' height='90'>$detail[qxb_def]</td>
<td width='50' height='90'>$detail[quantity_def]</td>
</tr>
</table>";
$pdf->WriteHTML($html);
}
$pdf->Output();
i need to show
<td>
$detail[name]
$detail[vase]
$detail[quality]
</td>

Outlook Receiving Mails in HTML Code

In my project i have done some email code to receive the order details, 1 mail to admin and other mail for user..
But some users and admins are receiving the emails with html code.. I checked in many ways with gmail, webmail.. All are displaying good.. Finally I tested with outlook and in outlook mail was getting in html code.. By enquiring the users they said that they r using outlook.. So that issue was with outlook I think so..
Can anyone help me to solve this issue.. Here is the source code which was used for displaying in email message.
$to = $obj_check_out->email;
$subject = "NEW YORK PRODUCT ORDER";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Instyle Customer Accounts <vamsi#mail.com>" . "\r\n";
$message = '<table width="100%" align="center">
<tbody><tr><td bgcolor="#393939">
<br>
<br>
<table cellspacing="0" cellpadding="0" width="650" border="0" align="center">
<tbody>
<tr>
<td width="10" bgcolor="#efefef">
<img src="images/newsletter/top_left.jpg" class="CToWUd">
</td>
<td width="630" height="92" bgcolor="#efefef" background="images/newsletter/top_bg.jpg">
<table width="630">
<tbody>
<tr>
<td width="514">
<font color="#333333" style="font-family:Tahoma;font-size:12px">
<br>
<b><a target="_blank" href="#"><span class="il">NEWYORK</span>.COM</a> ORDER CONFIRMATION</b> </font>
<font color="#333333" style="font-family:Tahoma;font-size:10px">[ DATE: '.$response["date_ordered"].' ]</font>
</td>
<td width="104" align="right">
<font color="#333333" style="font-family:Tahoma;font-size:12px">
<br>
<b>ORDER#:</b></font>
<font color="#333333" style="font-family:Tahoma;font-size:10px"> '.$response["order_log_id"].'</font>
</td>
</tr>
</tbody>
</table>
<br>
</td>
<td width="10" bgcolor="#efefef">
<img src="images/newsletter/top_right.jpg" class="CToWUd">
</td>
</tr>
<tr>
<td bgcolor="#efefef"> </td>
<td bgcolor="#efefef">
<font color="#333333">
<table cellspacing="0" cellpadding="2" width="630" border="0">
<tbody>
<tr>
<td height="35" bgcolor="#767676" background="images/newsletter/bar_bg.jpg" colspan="2">
<font color="#ffffff" style="font-family:Tahoma;font-size:12px">
<b>SHIPPING DETAILS</b></font>
</td>
</tr>
<tr>
<td width="170"> <font style="font-family:Tahoma;font-size:10px"><b>Name :</b></font></td>
<td width="452"><font style="font-family:Tahoma;font-size:10px">'.$response["firstname"].' '.$response["lastname"].'</font></td>
</tr>
<tr>
<td> <font style="font-family:Tahoma;font-size:10px"><b>Address :</b></font></td>
<td><font style="font-family:Tahoma;font-size:10px">'.$response["ship_address1"].' '.$response["ship_address2"].'</font></td>
</tr>
<tr>
<td> <font style="font-family:Tahoma;font-size:10px"><b>City :</b></font></td>
<td><font style="font-family:Tahoma;font-size:10px">'.$response["ship_city"].'</font></td>
</tr>
<tr>
<td> <font style="font-family:Tahoma;font-size:10px"><b>State :</b></font></td>
<td><font style="font-family:Tahoma;font-size:10px">'.$response["ship_state"].'</font></td>
</tr>
<tr>
<td> <font style="font-family:Tahoma;font-size:10px"><b>Country :</b></font></td>
<td><font style="font-family:Tahoma;font-size:10px">'.$response["ship_country"].'</font></td>
</tr>
<tr>
<td> <font style="font-family:Tahoma;font-size:10px"><b>Zip :</b></font></td>
<td><font style="font-family:Tahoma;font-size:10px">'.$response["ship_zipcode"].'</font></td>
</tr>
<tr>
<td> <font style="font-family:Tahoma;font-size:10px"><b>Phone :</b></font></td>
<td><font style="font-family:Tahoma;font-size:10px">'.$response["telephone"].'</font></td>
</tr>
<tr>
<td> <font style="font-family:Tahoma;font-size:10px"><b>Email :</b></font></td>
<td><font style="font-family:Tahoma;font-size:10px"><a target="_blank" href="mailto:'.$response["email"].'">'.$response["email"].'</a></font></td>
</tr>
<tr>
<td> <font style="font-family:Tahoma;font-size:10px"><b>Courier :</b></font></td>
<td><font style="font-family:Tahoma;font-size:10px">'.$response["courier"].'</font></td>
</tr>
</tbody>
</table>
<br>
<table cellspacing="0" cellpadding="2" width="630" border="0">
<tbody><tr>
<td background="images/newsletter/bar_bg.jpg" align="center"><font color="#a1a1a1" style="font-family:Tahoma;font-size:11px"><b>Thumb</b></font></td>
<td background="images/newsletter/bar_bg.jpg" align="center"><font color="#a1a1a1" style="font-family:Tahoma;font-size:11px"><b>Item</b></font></td>
<td background="images/newsletter/bar_bg.jpg" align="center"><font color="#a1a1a1" style="font-family:Tahoma;font-size:11px"><b>Style Number</b></font></td>
<td background="images/newsletter/bar_bg.jpg" align="center"><font color="#a1a1a1" style="font-family:Tahoma;font-size:11px"><b>Size</b></font></td>
<td background="images/newsletter/bar_bg.jpg" align="center"><font color="#a1a1a1" style="font-family:Tahoma;font-size:11px"><b>Color</b></font></td>
<td background="images/newsletter/bar_bg.jpg" align="center"><font color="#a1a1a1" style="font-family:Tahoma;font-size:11px"><b>Quantity</b></font></td>
<td background="images/newsletter/bar_bg.jpg" align="center"><font color="#a1a1a1" style="font-family:Tahoma;font-size:11px"><b>Price</b></font></td>
<td background="images/newsletter/bar_bg.jpg" align="center"><font color="#a1a1a1" style="font-family:Tahoma;font-size:11px"><b>Subtotal</b></font></td>
</tr>
'.$ordermsg.'
<tr>
<td align="right" colspan="7"><font style="font-family:Tahoma;font-size:12px">Grand-Total : </font></td>
<td align="right"><font style="font-family:Tahoma;font-size:12px">$'.$grandtotal.'</font></td>
</tr>
<tr>
<td align="right" colspan="7"><font style="font-family:Tahoma;font-size:9px">( For countries other than United State, you will be contacted by customer service for shipping fees ) </font></td>
<td align="center"></td>
</tr>
<tr>
<td align="center" colspan="8"><font style="color:red;font-family:Tahoma;font-size:9px"><br><br>* NOTE: Your order was received and will ship according to the availability notice on product page. </font><br></td>
</tr>
</tbody></table>
<table width="630" align="center" style="border-top:1px solid black">
<tbody><tr>
<td width="630" align="center">
<font color="#333333" style="font-family:Tahoma;font-size:10px">
<span class="il">Instyle</span> <span class="il">New</span> <span class="il">York</span>
230 West 38th Street
<span class="il">New</span> <span class="il">York</span>, NY 10018
PHONE: 212-840-0846 ext 22 EMAIL <a target="_blank" href="mailto:vamsi#gmail.com">info#<span class="il">company</span>.com</a>
</font>
</td>
</tr>
<tr>
<td width="630" align="center">
<font color="#333333" style="font-family:Tahoma;font-size:10px">
Purchaser agrees to abide by the <a target="_blank" href="#"><span class="il">company</span>.com</a> return policy.
</font>
</td>
</tr>
</tbody></table>
</font>
</td>
<td bgcolor="#efefef"> </td>
</tr>
<tr>
<td><img src="images/newsletter/bottom_left.jpg" class="CToWUd"></td>
<td><img src="images/newsletter/bottom_bg.jpg" class="CToWUd"></td>
<td><img src="images/newsletter/bottom_right.jpg" class="CToWUd"></td>
</tr>
</tbody>
</table>
<br><br>
</td></tr>
</tbody>
</table>';
mail($to,$subject,$message,$headers);
The email in outlook getting the same html code of $message with containing order details..
Thanks
If your code doesn't contain a valid <!doctype html> declaration and <body> tags etc, then that could contribute to the problem.
People using Outlook (or other similar mail clients) may have their settings set to not display HTML and images. I have seen that happen quite often before.
This stands at being a local issue and you have no control over that.
Therefore, you need to include a seperate header as TEXT only which is the usual norm when sending mail.
Use Phpmailer or Swiftmailer. That should solve everything.
References:
https://github.com/PHPMailer/PHPMailer
http://phpmailer.worxware.com/
http://swiftmailer.org/
and read the documentation on its implementation.
Other options are to use services such as MailChimp, Constant Contact etc. which work well and are services that are used widely and are already setup to handle both HTML and plain text formats.
http://mailchimp.com/
http://www.constantcontact.com/

Convert HTML table to CSV via PHP

I am trying to pull each td element from the html table below and import each element into its own cell in a CSV file.
Here are the two html tables:
<table width="100%" border="0" cellspacing="1" cellpadding="0" bgcolor="#006699">
<tr align="center" class="tableRow1Font">
<td width="7%">WAITLIST</td>
<td width="5%">91630</td>
<td width="11%">
ACCY 2001
</td>
<td width="5%">10</td>
<td width="16%">Intro Financial Accounting</td>
<td width="6%">3.00</td>
<td width="8%"> Zou, Y</td>
<td width="8%"><A HREF="http://www.gwu.edu/~map/building.cfm?BLDG=DUQUES" target="_blank"
>DUQUES</a> 251</td>
<td width="13%">TR<br>09:35AM - 10:50AM</td>
<td width="14%">
01/13/14 - 04/28/14
</td>
<td width="7%">
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="0" bgcolor="#006699">
<tr align="center" class="tableRow2Font">
<td width="7%">WAITLIST</td>
<td width="5%">90003</td>
<td width="11%">
ACCY 2001
</td>
<td width="5%">11</td>
<td width="16%">Intro Financial Accounting</td>
<td width="6%">3.00</td>
<td width="8%"> Zou, Y</td>
<td width="8%"><A HREF="http://www.gwu.edu/~map/building.cfm?BLDG=DUQUES" target="_blank"
>DUQUES</a> 254</td>
<td width="13%">TR<br>11:10AM - 12:25PM</td>
<td width="14%">
1/13/14 - 04/28/14
</td>
<td width="7%">
</td>
</tr>
</table>
I have written code that goes through the tables and pulls the td elements:
foreach($html->find('tr[align=center] td') as $e)
$str .= strip_tags($e->innertext) . ', ';
echo $str;
So how can I extract these elements into a CSV file? In Excel I want it to look like this with each td element in its own cell, starting a new row for each html table:
WAITLIST 91630 ACCY 2001 10 Intro Financial Accounting 3.00 Zou, Y DUQUES 251 TR
WAITLIST 90003 ACCY 2001 11 Intro Financial Accounting 3.00 Zou, Y DUQUES 251 TR
There is a library exist for this. Goto http://phpexcel.codeplex.com/. Download the zip file and in example you would find 17html.php try this code. I hope this will help.
CSV means Comma Separated Values. Thus, as you echo out the data (after running it through your function to strip the <td> tags), put commas in between each piece of data (cell), and a new line where you want the next line to start.
So to use your example above, it should look like this:
WAITLIST,91630,ACCY,2001,10,Intro Financial Accounting,3.00,Zou,Y,DUQUES,251,TR
WAITLIST,90003,ACCY,2001,11,Intro Financial Accounting,3.00,Zou,Y,DUQUES,2,
Keep in mind that when you echo this, you shouldn't have any other html tags or anything.

PHP Email TABLE format not working in code

I'm trying to figure out how to apply attributes to my table via php email. I can't get the background and and rowspan to work. Can't figure it out.
$to = 'XXXXX';
$subject = 'New Homeless Connection';
$msg = "<html>
<head>
<title>New Homeless Connection</title>
</head>
<body>
<table cellspacing=\"0\" cellpadding=\"10\" border=\"1\" align=\"left\">
<tr>
<td align=\"left\" width=\"150px\" background=\"#EEEEEE\">Registery No.:</td>
<td align=\"left\"> $reg</td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">First Name:</td>
<td align=\"left\">$first_name </td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">Connection Date:</td>
<td align=\"left\"$>$connect_date</td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">Probability:</td>
<td align=\"left\"$>$prob</td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">Volunteer Name:</td>
<td align=\"left\"$><strong>$hv_name</strong></td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">Volunteer Phone:</td>
<td align=\"left\"$><strong>$hv_phone</strong></td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">Consent Form:</td>
<td align=\"left\"$>$consent</td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">Field Count:</td>
<td align=\"left\"$>$reg_count</td>
</tr>
<tr>
<td align=\"left\" rowspan=\"2\">http://wwww.41q.org/admin/</td>
</tr>
</table>
</body>
</html>
";
A few things about tables:
You don't use "px" to define the width/height. Should just be width="150"
The background attribute should be bgcolor, and it doesn't use #. Just set bgcolor="eeeeee"
Why do you have $'s like this? <td align=\"left\"$> . Those shouldn't be there.
The rowspan is OK, but it's not doing anything because there is no row below it. I'm not sure what you are trying to do with the rowspan.
rowspan should be colspan, as your table has two columns all the way down except for the last row (whose cell needs to span both columns).
Also, background should be bgcolor.
I've posted up a sample with the replacement here: http://jsfiddle.net/8ymMh/4/
The gridlines show the last cell spanning both columns and the background colours come through OK.
I freely admit to have taken onboard AndrewR's suggestion of removing the hash from in front of the colour name (eeeeee) so all credit to him for that.

Can php code execute while creation of pdf using tcpdf?

I m working on module in which i have to make pdf from php page. I m Using tcpdf for that but m facing one problem that file contain some mysql queries and php coding which is not executed by pdf page.
$prn_no = $_POST['prn_no'];
$current_sem = $_POST['current_sem'];
$qr_fetch_sem_res_id = mysql_query("SELECT * FROM table1 WHERE ((prn='$prn_no') AND (semisterName='$current_sem'))")or die(mysql_error());
$qr_fetch_sem_result_ans = mysql_fetch_array($qr_fetch_sem_res_id);
<tr>
<td colspan="11" align="left" valign="middle">Programme Name: <?php echo $qr_fetch_sem_result_ans['programme_name'];?></td>
</tr>
<tr>
<td colspan="11" align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="27%">Seat No.: <?php echo $qr_fetch_sem_result_ans['seatNo'];?></td>
<td width="3%"> </td>
<td width="22%">PR No. : <?php echo $qr_fetch_sem_result_ans['prn'];?></td>
<td width="2%"> </td>
<td width="17%">Semester : <?php echo $qr_fetch_sem_result_ans['semisterName'];?></td>
<td width="1%"> </td>
<td width="25%">Month / Year Of Exam : <?php echo $qr_fetch_sem_result_ans['month_year_of_exam'];?> </td>
<td width="3%"> </td>
</tr>
<tr>
<td colspan="3">Name: <?php echo $qr_fetch_sem_result_ans['student_name'];?></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="7">College / Institute: <?php echo $qr_fetch_sem_result_ans['institute_name'];?></td>
<td> </td>
</tr>
</table></td>
</tr>
I'm going to go out on a limb here and suggest that you run your queries fist and then build your pdf file. If you run the queries after you build the pdf then of course it will not have access to your data. If that doesn't help then I must not understand what you're asking.

Categories