How to disable header repeat in new page mpdf library? - php

I add <table repeat_header="0" > but it doesn't work for me. I want thead html tag only show in first page.
<table>
<thead>
<tr>
<th>#</th>
<th>First</th>
<th>Last</th>
<th>Handle</th>
</tr>
</thead>
<tbody>
....
</table>
My mpdf config is:
$mpdf = new mPDF('s');
$mpdf->SetDisplayMode('fullpage');
$file_name = $_SESSION["file_name"];
$html = $_SESSION['pdf'];
$html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
$mpdf->WriteHTML($html);
$mpdf->Output($file_name, 'F');
$mpdf->Output();

Do not use the <thead> element, use only simple table row with <th> cells.
<table>
<tr>
<th>#</th>
<th>First</th>
<th>Last</th>
<th>Handle</th>
</tr>
<tbody>
....
</table>
There is no other way to achieve this in mPDF.

vendor\mpdf\mpdf\src\Tag\THead.php
vendor\mpdf\mpdf\src\Tag\TFoot.php
$this->mpdf->tablethead = 1; to --> $this->mpdf->tablethead = 0;
$this->mpdf->tabletfoot = 1; to --> $this->mpdf->tabletfoot = 0;

Related

Table heading on every page using MPDF

I want the table heading to be displayed on each page while generating pdf using MPDF library.
$mpdf = new \Mpdf\Mpdf([
'mode'=>'utf-8',
'format' => 'A4-L'
]);
$mpdf->SetHTMLHeader("<table>
<tr>
<th>Sl No.</th>
<th>Name</th>
</tr>
");
for($i=0; $i<500;$i++){
$mpdf->WriteHTML("<tr>");
$mpdf->WriteHTML("<td>".$res[$i]["slno"]."</td>");
$mpdf->WriteHTML("<td>".$res[$i]["name"]."</td>");
$mpdf->WriteHTML("</tr>");
}
$mpdf->WriteHTML("</table>");
Just use a <thead> tag. Outside the page header.
$mpdf->WriteHTML('
<table>
<thead>
<tr>
<th>Sl No.</th>
<th>Name</th>
</tr>
<thead>
...');
https://mpdf.github.io/tables/tables.html#repeating-table-header-row-on-new-page

Editing HTML table with PHP DOM

I've tried to add a column to a table I've loaded to the DOM function but can't get this code working.
<?php
$dom = new DOMDocument();
$dom->loadHTML('<table>
<tbody>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
</tbody>
</table>');
$tr = $dom->getElementsByTagName('tr');
$th = $dom->createElement('th', 'Comment');
$tr->item(0)->appendChild($th);
Your code is working fine. You successfully add a new th element to the DOM tree. But you need to output it to the browser with
echo $dom->saveHTML();
The output in HTML is:
<html>
<body>
<table>
<tbody>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Comment</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
</tbody>
</table>
</body>
</html>

PHP Dompdf Format HTML

I am new to using dompdf, I am unable to use a css file or just inline css to alter the formatting of the pdf I am having created. I would like to change the size of my font, the color, and cell colors for my table. I am not sure how to make this work using Dompdf. Thank you for the help! I have some examples of how I was attempting to do it in my code.
HTML/PHP Code:
$week_ending_date = date("m-d-Y", strtotime('this friday'));
$table = "table";
$tableBackground = "background: red";
$four = "2";
$pdf = "<html>
<head><title>Weekly Report</title></head>
<body>
<basefont size=".$four.">
<center><h4>Citations</h4>";
$pdf .= "<h4>".$pdfTimeFrame."</h4>";
$pdf .= "<h4>All Items from ".$Start." to ".$End."</h4></center>";
$pdf .= "<div id=".$table.">
<table style=".$tableBackground.">
<thead>
<tr>
<th>Week Ending</th>
<th>W Number</th>
<th>Project Title</th>
<th>Project Contact</th>
<th>N Number</th>
<th>Verified By</th>
<th>Date Verified</th>
<th>Comments</th>
<th>Notes</th>
<th>Received</th>
</tr>
</thead>
<tbody>";
while($row = oci_fetch_array($runQuery, OCI_ASSOC+OCI_RETURN_NULLS))
{
$WNumber = $row['P_NUMBER']."-".$row['A_NUMBER'];
$querySQLDB = "SELECT [Verified_By], [Comments], [Notes], [Date_Verified], [Week_Ending], [Date_Received]
FROM dbo.Information
WHERE dbo.Information.Key_ID = '$WNumber'
ORDER BY dbo.Information.ID DESC";
$dbe->query($querySQLDB);
$sqlData = $dbe->fetch();
$WeekEndingLessTime = str_replace("12:00:00:000AM"," ",$sqlData['Week_Ending']);
$dateNoTime = str_replace("12:00:00:000AM"," ",$sqlData['Date_Verified']);
$dateReceived = str_replace(":00:000"," ",$sqlData['Date_Received']);
$pdf .= "<tr>
<td>
".$week_ending_date."
</td>
<td>
".$WNumber."
</td>
<td>
".$row['TITLE']."
</td>
<td>
".$row['PROJECT_MANAGER_N']."
</td>
<td>
".$row['PROJECT_MANAGER_O']."
</td>
<td>
".$sqlData['Verified_By']."
</td>
<td>
".$dateNoTime."
</td>
<td>
".$sqlData['Comments']."
</td>
<td>
".$sqlData['Notes']."
</td>
<td>
".$dateReceived."
</td>
</tr>
";
}
$pdf .= " </tbody>
</table>
</div>";
$pdf .= "</body></html>";
$dompdf = new DOMPDF();
$dompdf->load_html($pdf);
$dompdf->render();
$dompdf->stream("Report_'".$week_ending_date."'.pdf", $pdf);
$pdf = "<html>
<head>
<style>
body{
color: blue;
}
</style>
<title>Weekly Report</title>
</head>
Basically I was trying to format in the wrong place. It's working now though.

Extract Value from HTML using PHP

I'm retrieving a HTML page using cURL. The html page has a table like this.
<table class="table2" style="width:85%; text-align:center">
<tr>
<th>Refference ID</th>
<th>Transaction No</th>
<th>Type</th>
<th>Operator</th>
<th>Amount</th>
<th>Slot</th>
</tr>
<tr>
<td>130717919020ffqClE0nRaspoB</td>
<td>8801458920369</td>
<td>Purchase</td>
<td>Visa</td>
<td>50</td>
<td>20130717091902413</td>
</tr>
</table>
This is the only table in that HTML page. I need to extract Refference ID & Slot using PHP.
But no idea how that can be done.
EDIT:
This one helped me a lot.
A regex based solution like the accepted answer is not the right way to extract information from HTML documents.
Use a DOMDocument based solution like this instead:
$str = '<table class="table2" style="width:85%; text-align:center">
<tr>
<th>Refference ID</th>
...
<th>Slot</th>
</tr>
<tr>
<td>130717919020ffqClE0nRaspoB</td>
...
<td>20130717091902413</td>
</tr>
</table>';
// Create a document out of the string. Initialize XPath
$doc = new DOMDocument();
$doc->loadHTML($str);
$selector = new DOMXPath($doc);
// Query the values in a stable and easy to maintain way using XPath
$refResult = $selector->query('//table[#class="table2"]/tr[2]/td[1]');
$slotResult = $selector->query('//table[#class="table2"]/tr[2]/td[6]');
// Check if the data was found
if($refResult->length !== 1 || $slotResult->length !== 1) {
die("Data is corrupted");
}
// XPath->query always returns a node set, even if
// this contains only a single value.
$refId = $refResult->item(0)->nodeValue;
$slot = $slotResult->item(0)->nodeValue;
echo "RefId: $refId, Slot: $slot", PHP_EOL;
$str = '<table class="table2" style="width:85%; text-align:center">
<tr>
<th>Refference ID</th>
<th>Transaction No</th>
<th>Type</th>
<th>Operator</th>
<th>Amount</th>
<th>Slot</th>
</tr>
<tr>
<td>130717919020ffqClE0nRaspoB</td>
<td>8801458920369</td>
<td>Purchase</td>
<td>Visa</td>
<td>50</td>
<td>20130717091902413</td>
</tr>
</table>';
preg_match_all('/<td>([^<]*)<\/td>/', $str, $m);
$reference_id = $m[1][0];
$slot = $m[1][5];

How to convert Html code to template output in browser

I need to convert HTML in template.
As seen in image content should show as a template.
I am using table to show . but now i need to show it in template output
Here is my Code:
<table id="datatable" class="tablesorter">
<span id='errfrmMsg'></span>
<thead>
<tr>
<th scope="col" id="">Name</th>
<th scope="col" id="">Content</th>
</tr>
</thead>
<tbody>
<?php
$templ_id = $_REQUEST['templ_id'];
$getTemplateQuery = mysql_query("select * from templates where id = $templ_id");
$getTemplateRow = mysql_fetch_array($getTemplateQuery);
?>
<tr>
<td valign="top" width="125"><?php echo $getTemplateRow['templ_name'];?></td>
<td valign="top" width="319">
<?php
echo $templContent = $getTemplateRow['templ_content'];
?>
</tr>
</tbody>
</table>
Here is an Output:
From what I can gather from your question, try outputting with:
$html = htmlspecialchars_decode($content)
EDIT:
echo $templContent = htmlspecialchars_decode($getTemplateRow['templ_content']);
Try this this will help You
<?php
echo $htmlContent = htmlspecialchars_decode($getTemplateRow['templ_content'])
?>

Categories