pdf not generate domPdf php codeigniter - php

I want PDF separate html(invoice.html) page using DomPDF library,
but when I generating html file to PDF its throwing error like: it would throwing error regarding style sheet.
'DOMXPath::query(): Invalid expression' (length=37)
D:\wamp\www\crm\include\dompdf\src\Css\Stylesheet.php:882:string
html file:-
1)invoice.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Invoice</title>
</head>
<body style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #000000;">
<div style="width: 680px;">
<table style="border-collapse: collapse; width: 100%; border-top: 1px solid #DDDDDD; border-left: 1px solid #DDDDDD; margin-bottom: 20px;">
<tr>
<td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: left; padding: 7px; color: #222222;" colspan="2">Order Details</td>
</tr>
<tr>
<td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;">
<b>Invoice Id</b> {{invoice_id}}<br />
<b>Date</b> {{date}}<br />
<b>Payment</b> {{payment_method}}<br />
</td>
<td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;">
<b>Address</b> {{store_address}}<br />
<b>Telephone</b> {{store_telephone}}<br />
<b>GSTIN</b> {{store_gstin}}<br />
</td>
</tr>
</table>
<table style="border-collapse: collapse; width: 100%; border-top: 1px solid #DDDDDD; border-left: 1px solid #DDDDDD; margin-bottom: 20px;">
<tr>
<td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: left; padding: 7px; color: #222222;" colspan="3">Customer Details</td>
</tr>
<tr>
<td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;">
<b>GSTIN</b> {{customer_gstin}}<br />
<b>Telephone</b> {{customer_number}}<br />
<b>Address</b> {{customer_address}}<br />
</td>
</tr>
</table>
<table style="border-collapse: collapse; width: 100%; border-top: 1px solid #DDDDDD; border-left: 1px solid #DDDDDD; margin-bottom: 20px;">
<thead>
<tr>
<td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: left; padding: 7px; color: #222222;">Product</td>
<td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: right; padding: 7px; color: #222222;">Quantity</td>
<td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: right; padding: 7px; color: #222222;">Price</td>
<td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: right; padding: 7px; color: #222222;">Total</td>
</tr>
</thead>
<tbody>
{{products}}
</tbody>
<tfoot>
{{totals}}
</tfoot>
</table>
</div>
</body>
</html>
controller:-
2)sales.php(codeigniter controller)
$dompdf = new dompdf();
$sourcefile = file_get_contents(webpath.'include/invoice.html');
$original = array("{{invoice_id}}","{{date}}","{{payment_method}}","{{store_address}}","{{store_telephone}}","{{store_gstin}}","{{customer_gstin}}","{{customer_number}}","{{customer_address}}","{{products}}","{{totals}}");
$replace = array($invoice_id,$date,ucfirst($datas['payConition']),$storedata['store_address'],$storedata['store_telephone'],$storedata['store_gstIn'],$users['party_gstin'],$users['party_number'],$users['party_address'],$producttext,$totaltext);
$printfile = str_replace($original, $replace, $sourcefile);
$dompdf->loadHtml($printfile);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
//$d

Related

Codeigniter Dompdf can't remove the black footer.

I am using dompdf in codeigniter, the HTML page looks fine but in dompdf generated pdf, there is a black box.
The code in the footer section is:
<div class="signature-footer">
<table>
<tr>
<td style="text-align: center;border-style:dashed; border-top:1px black;border-bottom:1px solid white; border-left:1px solid white; border-right:1px solid white;">Prepared By<br><?php echo $quotation_detail[0]->employee_name; ?><br><?php echo $quotation_detail[0]->designation_name ; ?></td>
<td style="width: 30%;border-top:1px solid white;border-bottom:1px solid white; border-left:1px solid white; border-right:1px solid white;"> </td>
<td style="text-align: center;border-top:1px solid white;border-bottom:1px solid white; border-left:1px solid white; border-right:1px solid white;"> </td>
<td style="width: 30%;border-top:1px solid white;border-bottom:1px solid white; border-left:1px solid white; border-right:1px solid white;"> </td>
<td style="text-align: center;border-style:dashed; border-top:1px black;border-bottom:1px solid white; border-left:1px solid white; border-right:1px solid white;">Authorized Signature<br> <br> </td>
</tr>
</table>
</div>
</div><div class="below-border-footer"></div><div style="text-align: center"><img src="<?php echo base_url(); ?>interface/img/footerImage.png"> </div></div></body>
</html>
CSS for these two elements:
.below-border-footer {
width: 100%;
border-top: 0 ;
padding-bottom: 0;
text-align: center;
}
.signature-footer {
font-size: 12px;
font-weight: bold;
width: 100%;
position: relative;
margin-top: 70px;
margin-bottom: 2px;
}
I've tried for hours but no result. How can I remove the black box in the footer?

How to add a <!-- message --> to an email for parsing?

I am writing a code that will take a user reply to an automated message and parse out any previous discussion. then take the body of the new email and insert it into a database.
I thought I can add <!-- This is the message break --> to the very top of my message and from there I can remove anything under this phrase when reading the email. using something like this
$newReply = strstr($message, '<!-- This is the message break -->',true);
But for some reason the email server seems to be removing the page break that I added (ie. <!-- This is the message break -->) I can't find it in the email.
Here is the html code that I am using to send it as an email using php mail() function.
<!-- This is the message break -->
<html>
<body>
<table rules="all" style="padding: 10px; line-height: 1.42857143; vertical-align: Middle; border: 5px solid #1A1A1C; width: 780px; border-collapse: collapse; border-spacing: 0;" cellspacing="0">
<tr>
<td colspan="2" style="text-align: center; background-color: #1A1A1C; color: #fff; padding: 5px;">Need to respond? Just hit reply, a responses will be appended to ticket details automatically</td>
</tr>
<tr>
<td width="100" style="color: #333333; font-weight: bold; border-top: 1px solid #DBDBDB; border-right: 1px solid #DBDBDB; border-bottom: 1px solid #DBDBDB; border-left: 5px solid #1A1A1C; background-color: #F0F0F0;">Subject</td>
<td style="color: #333333; border-top: 1px solid #DBDBDB; border-right: 5px solid #1A1A1C; border-bottom: 1px solid #DBDBDB; border-left: 1px solid #DBDBDB; background-color: #F0F0F0;">'.strip_tags($ticketInfo['title']).'</td>
</tr>
<tr>
<td width="100" style="color: #333333; font-weight: bold; border-top: 1px solid #DBDBDB; border-right: 1px solid #DBDBDB; border-bottom: 1px solid #DBDBDB; border-left: 5px solid #1A1A1C;">Ticket #</td>
<td style="color: #333333; border-top: 1px solid #DBDBDB; border-right: 5px solid #1A1A1C; border-bottom: 1px solid #DBDBDB; border-left: 1px solid #DBDBDB; ">'.$ticketInfo['issue_id'].'</td>
</tr>
<tr>
<td width="100" style="color: #333333; font-weight: bold; border-top: 1px solid #DBDBDB; border-right: 1px solid #DBDBDB; border-bottom: 1px solid #DBDBDB; border-left: 5px solid #1A1A1C; background-color: #F0F0F0;">Notification</td>
<td style="color: #333333; border-top: 1px solid #DBDBDB; border-right: 5px solid #1A1A1C; border-bottom: 1px solid #DBDBDB; border-left: 1px solid #DBDBDB; background-color: #F0F0F0;">'.$ticketInfo['notificationType'].'</td>
</tr>
<tr>
<td width="100" style="color: #333333; font-weight: bold; border-top: 1px solid #DBDBDB; border-right: 1px solid #DBDBDB; border-bottom: 1px solid #DBDBDB; border-left: 5px solid #1A1A1C;">Status</td>
<td style="color: #333333; border-top: 1px solid #DBDBDB; border-right: 5px solid #1A1A1C; border-bottom: 1px solid #DBDBDB; border-left: 1px solid #DBDBDB; ">'.$ticketInfo['ticketStatus'].'</td>
</tr>
<tr>
<td width="100" style="color: #333333; font-weight: bold; border-top: 1px solid #DBDBDB; border-right: 1px solid #DBDBDB; border-bottom: 1px solid #DBDBDB; border-left: 5px solid #1A1A1C; background-color: #F0F0F0;">Priority</td>
<td style="color: #333333; border-top: 1px solid #DBDBDB; border-right: 5px solid #1A1A1C; border-bottom: 1px solid #DBDBDB; border-left: 1px solid #DBDBDB; background-color: #F0F0F0;">'.$ticketInfo['priority']. ' - ' . $ticketInfo['ticket_type'] .'</td>
</tr>
<tr>
<td width="100" style="color: #333333; font-weight: bold; border-top: 1px solid #DBDBDB; border-right: 1px solid #DBDBDB; border-bottom: 1px solid #DBDBDB; border-left: 5px solid #1A1A1C;">Ticket Assigned To</td>
<td style="color: #333333; border-top: 1px solid #DBDBDB; border-right: 5px solid #1A1A1C; border-bottom: 1px solid #DBDBDB; border-left: 1px solid #DBDBDB; ">'.$ticketInfo['assigned_to'].'</td>
</tr>
<tr>
<td width="100" style="color: #333333; font-weight: bold; border-top: 1px solid #DBDBDB; border-right: 1px solid #DBDBDB; border-bottom: 1px solid #DBDBDB; border-left: 5px solid #1A1A1C; background-color: #F0F0F0;">Client Name</td>
<td style="color: #333333; border-top: 1px solid #DBDBDB; border-right: 5px solid #1A1A1C; border-bottom: 1px solid #DBDBDB; border-left: 1px solid #DBDBDB; background-color: #F0F0F0;">'.$ticketInfo['client_name'].'</td>
</tr>
<tr>
<td colspan="2">
'.$notes.'
<br /><br /><strong><em>To comment on this ticket, you can either replay directly to this email, or click the link below to view previous comments</em></strong><br />
<a href="'.$url .'"><em>Click Here To View This Ticket</em><a/><br /><br />
</td>
</tr>
</table>
</body></html>

Simple_html_dom find table with custom style

How to find table with style? I know it have style attr:
style="border: 1px solid #aaaaaa; border-collapse: collapse; width: 600px; background: #ffffff; text-align: center; margin-top: 10px;"
but how to use it with "find"?
I tried:
$scrap['content']->find('table[style*=border: 1px solid #aaaaaa; border-collapse: collapse; width: 600px; background: #ffffff; text-align: center; margin-top: 10px;]');
but its not working
It works for me:
require_once('simple_html_dom.php');
$html = <<<EOF
<table>foo</table>
<table style="border: 1px solid #aaaaaa; border-collapse: collapse; width: 600px; background: #ffffff; text-align: center; margin-top: 10px;">bar</table>
EOF;
$doc = str_get_html($html);
echo $doc->find('table[style*=border: 1px solid #aaaaaa; border-collapse: collapse; width: 600px; background: #ffffff; text-align: center; margin-top: 10px;]', 0)->text();
//=> bar

How can I make a table column width somewhat similar automatically?

I wrote a PHP code to generate a table dynamically. The head of the table can be any text value in a database and the column of the table can be any text in the database.
If the value of the columns are the same or similar, then the width should be somewhat the same.
the following is my HTML code that is generated by PHP
<div style="margin: 0 auto; text-align: center;">
<table class="common2">
<thead>
<tr>
<th colspan="12">Title</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left; width: 150px;">Answer Options</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">11+</td>
</tr>
<tr>
<td style="text-align: left; width: 150px;">Response Count</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">1</td>
</tr>
</tbody>
</table>
</div>
this is my common2 css code
.common2
{
width: 100%;
border: solid #E6E6E6 1px;
margin: 0 auto;
padding: 0;
border-spacing: 0px;
/* border-collapse: collapse; */
}
.common2 td
{
padding: 6px;
border: solid #E6E6E6 1px;
}
.common2 th
{
color: #fff;
font-weight: bold;
text-align: center;
border: solid #E6E6E6 1px;
background-color: #1A1A1C;
padding: 8px;
font-size: 14.5px;
}
.common2 th.highlighed
{
color: #fff;
font-weight: bold;
text-align: center;
border: 0px solid #DBDBDB;
background-color: #666666;
padding: 6px 10px;
}
.common2 tr:last-child td:last-child {
-moz-border-radius: 0 0 6px 0;
-webkit-border-radius: 0 0 6px 0;
border-radius: 0 0 6px 0;
}
.common tr:last-child td:last-child {
-moz-border-radius: 0 0 10px 10px;
-webkit-border-radius: 0 0 10px 10px;
border-radius: 0 0 10px 10px;
}
.common2 tr:nth-child(even)
{
background-color: #E8E8E8; /*#E7E9E8; /*#D6D8D7;*/
position: relative;
}
.common2 td.stickOut
{
background-color: #DDEAFA; /*#DBAFAF;*/
position: relative;
font-weight: bold;
border: solid #DBDBDB 1px;
}
.common2 td.head
{
background-color: #25328C; /* #4F4F4F; */
text-align: center;
border: 1px solid #25328C;
padding: 3px;
font-weight: bold;
color: #fff;
padding: 4px 10px;
height: 35px;
/* IE10 Consumer Preview */
background-image: -ms-linear-gradient(bottom, #2C3C92 0%, #25328C 100%);
/* Mozilla Firefox */
background-image: -moz-linear-gradient(bottom, #2C3C92 0%, #25328C 100%);
/* Opera */
background-image: -o-linear-gradient(bottom, #2C3C92 0%, #25328C 100%);
/* Webkit (Safari/Chrome 10) */
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #2C3C92), color-stop(1, #25328C));
/* Webkit (Chrome 11+) */
background-image: -webkit-linear-gradient(bottom, #2C3C92 0%, #25328C 100%);
/* W3C Markup, IE10 Release Preview */
background-image: linear-gradient(to top, #2C3C92 0%, #25328C 100%);
}
.common2 td.subfoot
{
background-color: #FFFF99; /* #4F4F4F; */
text-align: center;
border: 1px solid #DBDBDB;
padding: 3px;
color: #000;
font-weight: 600;
font-style:italic;
padding: 4px 10px;
}
.common2 td.foot1
{
background-color: #999999; /* #4F4F4F; */
text-align: center;
border: 1px solid #DBDBDB;
padding: 3px;
font-weight: bold;
color: #fff;
padding: 4px 10px;
}
.common2 td.foot2
{
background-color: #555555; /* #4F4F4F; */
text-align: center;
border: 1px solid #DBDBDB;
padding: 3px;
font-weight: bold;
color: #fff;
padding: 4px 10px;
}
Here is a screenshot of my current output.
How can I make those columns with a similar width, excluding the very first column, as I specified how wide that will be?
remove width property from .common2
http://jsfiddle.net/raam86/knj9E/

HTML table in Email

I have made the following email template,
but instead of shown data in table format; it shows the complete Html codes in the email body. Please help me fix this.
<table style="font-family: Lucida Sans Unicode, Lucida Grande, Sans-Serif; font-size: 12px; background: #fff; margin: 45px; width: 480px; border-collapse: collapse; text-align: left;" summary="Website Uptime Statistics">
<thead>
<tr>
<th style="font-size: 14px; font-weight: normal; color: #039; padding: 10px 8px; border-bottom: 2px solid #6678b1;" scope="col">#S.No.</th>
<th style="font-size: 14px; font-weight: normal; color: #039; padding: 10px 8px; border-bottom: 2px solid #6678b1;" scope="col">Website</th>
<th style="font-size: 14px; font-weight: normal; color: #039; padding: 10px 8px; border-bottom: 2px solid #6678b1;" scope="col">Status</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border-bottom: 1px solid #ccc; color: #669; padding: 6px 8px;">1</td>
<td style="border-bottom: 1px solid #ccc; color: #669; padding: 6px 8px;">http://google.com</td>
<td style="border-bottom: 1px solid #ccc; color: #669; padding: 6px 8px;">Up</td>
</tr>
<tr>
<td style="border-bottom: 1px solid #ccc; color: #009; padding: 6px 8px;">2</td>
<td style="border-bottom: 1px solid #ccc; color: #009; padding: 6px 8px;">http://google.com</td>
<td style="border-bottom: 1px solid #ccc; color: #009; padding: 6px 8px;">Down</td>
</tr>
<tr>
<td style="border-bottom: 1px solid #ccc; color: #669; padding: 6px 8px;">$300</td>
<td style="border-bottom: 1px solid #ccc; color: #669; padding: 6px 8px;">$300</td>
<td style="border-bottom: 1px solid #ccc; color: #669; padding: 6px 8px;">$300</td>
</tr>
</tbody>
</table>
Have you set the content-type of the email so the receiving email application knows it contains HTML and can therefore present it properly?
Content-Type: text/html; charset=UTF-8
$html = '';
$html .= ' <table style="font-family: Lucida Sans Unicode, Lucida Grande, Sans-Serif; font-size: 12px; background: #fff; margin: 45px; width: 480px; border-collapse: collapse; text-align: left;" summary="Website Uptime Statistics"><thead>';
.....
echo $html;
try this

Categories