All was going swimmingly with my export to PDF feature, until item which was being exported became quite long.
$cv_html = '
<!DOCTYPE HTML>
<table width="600px">
<thead>
<tr>
<td colspan="2">
<h1>Cv</h1>
</td>
<td colspan="4">
<h2>'.$user_details['name'].'</h2>
</td>
</tr>
<tr>
<td colspan="2">
</td>
<td colspan="4" class="textright">
<br>
'.$user_details['address1'].'<br>
'.$user_details['address2'].'<br>
'.$user_details['city'].'<br>
'.$user_details['county'].'<br>
'.$user_details['postcode'].'<br>
'.$user_details['mobile'].'
</td>
</tr>
</thead>
<tbody>
<tr class="">
<td class=""><br></td>
</tr>
';
/* Return getInvoices for EXPORT */
foreach ($ukapr->getCVsection() as $row) {
$hash = $row['hash'];
$cv_html .= '<tr bgcolor="#2D9484" class="head white">
<td colspan="3" class="white">
'.$row['sectionname'].'
</td>
</tr>';
if($ukapr->getCVrow($hash) !== null) {
foreach ($ukapr->getCVrow($hash) as $cvrow) {
$cv_html .= '<tr class="">
<p>'.$cvrow['cvbody'].'</p>
</tr>';
}
}
}
$cv_html .= '</tbody>
</table>
<style>
//Lots of css here
</style>
';
$ukapr->redirect('http://ukapr.co.uk/members/export_cv.php');
It exports if "'.$cvrow['cvbody'].'" is small, but if its long, say 400 words, it just spits out this error:
Notice: Undefined offset: 3 in /home/ukapr/public_html/dompdf/include/cellmap.cls.php on line 559
Fatal error: Call to a member function get_id() on a non-object in /home/ukapr/public_html/dompdf/include/cellmap.cls.php on line 560
Any help would be much appreciated.
Related
I am trying to render an HTML page as PDF in using DOMPDF version 0.8 on CodeIgniter running on Windows 7 64 bit. My development machine runs PHP 7 on XAMPP on a Windows 10 Pro but the production server runs PHP 5.6 on Windows 7 professional 64bit.
I realize that when I run the application on my local machine, everything works well and the PDF is properly generated with the images and styles properly displayed in place. But when I deploy to the production machine, the styles and the images dont render properly again. The images dont display and the styles are not rendered.
Please I will appreciate any suggestions to resolve this issue
Here are some parts of my codes below:
//Application/libraries/pdf.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once("./vendor/dompdf/dompdf/src/autoloader.php");
use Dompdf\Dompdf;
class Pdf
{
public function generate($html, $filename='', $stream=TRUE, $paper = 'A4',
$orientation = "landscape")
{
$dompdf = new DOMPDF();
$dompdf->loadHtml($html);
$dompdf->setPaper($paper, $orientation);
$dompdf->render();
if ($stream)
{
$dompdf->stream($filename.".pdf", array("Attachment" => 1));
}
else
{
return $dompdf->output();
}
}
}
//Application/controllers/report.php
...some code removed for brevity
$this->load->library('pdf');
$html=$this->load->view('parts/pdf-head',NULL,true);
$html.=$this->load->view('admin/reports/periodic/pdf',['results'=>$_SESSION['students_result']],true);
$this->pdf->generate($html,'report');
//Application/views/admin/reports/periodic/pdf.php
<?php
if(empty($results))
{
echo "<div class='alert alert-danger'><span class='fa fa-warning'></span> No result found in record for the selected parameters</div>";
}
else
{
foreach($results['scores'] as $student=>$scores)
{
?>
<table class="table table-bordered" style="padding: 10px">
<tr class="tr-row2">
<td colspan="16" style="text-align: center">
<?php echo img(['src'=>"style-resources/logo2.png", 'width'=>"50px"]);?>
</td>
</tr>
<tr class="tr-row2">
<td colspan="16" style="text-align: center">
<?php echo $results['campus'];?>
</td>
</tr>
<tr class="tr-row2">
<td colspan="16" style="text-align: center">
<?php echo $results['title'];?>
</td>
</tr>
<tr class="tr-row2">
<th colspan="10" style="text-align: left;">
<?php echo strtoupper($scores['student_info']['student_names']);?>
</th>
<td colspan="6">
<?php echo $scores['student_info']['class'].', '.$scores['student_info']['class_arm']; ?>
</td>
</tr>
<tr class="tr-row2">
<td colspan="7" style="text-align: right">Number of class contacts </td><td style="text-align: left"><?php echo $scores['student_info']['attendance'];?></td><td colspan="7" style="text-align: right">Student's Attendance</td><td style="text-align: left"><?php echo $scores['attendance_score'];?></td>
</tr>
<tr class="tr-row2">
<th>C.A.1 (10%)</th><td><?php echo $scores['ca1']; ?></td><th>C.A.2 (10%)</th><td><?php echo $scores['ca2']; ?></td><th>Classwork (15%)</th><td><?php echo $scores['classwork']; ?></td><th> Attendance (5%)</th><td><?php echo $scores['attendance_score'];?></td><th>EXAM (60%)</th><td><?php echo $scores['exam']; ?></td><th>TOTAL (100%)</th><td><?php echo $scores['total'];
?></td><th>Grade</th><td><?php echo $scores['grade']; ?></td><th>POSITION</th><td><?php $this->load->helper('ordinalize'); echo ordinalize(array_search($scores['total'],$_SESSION['result_total'])+1); ?></td>
</tr>
<tr class="tr-row2">
<th colspan="3">Highest Score</th><td><?php echo max($_SESSION['result_total']); ?></td><th>Lowest Score</th><td><?php echo min($_SESSION['result_total']); ?></td><th>Class Average</th><td><?php echo array_sum($_SESSION['result_total'])/count($_SESSION['students_result']['scores']) ?></td><th colspan="3">Effort</th><td colspan="5" style="text-align: left"><?php echo $scores['effort'];?> </td>
</tr>
<tr>
<th colspan="6">
<table class="table table-striped table-bordered">
<tr class="tr-row2">
<td colspan="2" style="text-align: center">
Accomplishments for the Term
</td>
</tr>
<tr class="tr-row2">
<th>Exercise/Activity</th>
<th>Score</th>
</tr>
<?php
if(empty($scores['scores'][1]))
{
echo "<tr class='tr-row2'><td colspan='2'><em> No lesson exercise found for this student</em></td></tr>";
}
else {
foreach ($scores['scores'][1] as $a => $b) {
if ($a != 'total') {
echo "<tr class='tr-row2'><th>" . $a . "</th><td>" . $b . "</td></tr>"; ?>
<?php }
}
}
?>
<tr class="tr-row2"><th colspan="2" style="text-align: center">Summary of report</th></tr>
<tr class="tr-row2">
<td colspan="2"><em><?php echo $scores['comment']; ?></em></td>
</tr>
</table>
</th>
<th colspan="10">
<table class="table table-striped">
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
Skills/Strengths demonstrated
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
<em><?php echo $scores['student_info']['skills'];?></em>
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
Observed Weakness(es)
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: Left">
<em><?php echo $scores['student_info']['weaknesses'];?></em>
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
Remedial steps taken
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
<em><?php echo $scores['student_info']['remedies'];?></em>
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
Further improvement steps to be taken
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
<em><?php echo $scores['student_info']['further_actions'];?></em>
</td>
</tr>
</table>
</th>
</tr>
<tr class="tr-row2">
<th colspan="4" style="text-align: right">Educator's Name</th><td colspan="4" style="text-align: left"><em><?php echo $results['educator']; ?></em></td><th colspan="4" style="text-align: right">Educator's Signature</th><td colspan="4"></td>
</tr>
<tr class="tr-row2">
<th colspan="4" style="text-align: right">Coordinator's Name</th><td colspan="4" style="text-align: left"><em><?php echo $results['coordinator'];?></em></td><th colspan="4" style="text-align: right">Coordinator's Signature</th><td colspan="4"></td>
</tr>
</table>
<?php }
}
.HTACCESS file looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
in this check your RewriteBase.
Then Check your application/config/config.php for $config['base_url'] = 'http://localhost/project_name'; line of code.
I have an html table like this
<table>
<tbody>
<tr>
<td><table>
<tbody>
<tr class="prdLi">
<td rowspan="2" class="prdNo"><span>310.</span></td>
<td colspan="2" class="prdDe" rowspan="2"><span>Pepsi</span></td>
</tr>
<tr class="prdLi">
<td class="prdAc"><span> 1.5L</span></td>
<td><span> </span></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
the table is saved as $html
I want to select the child elements of the class .prdLi
I tried like this:
foreach($html->find('tr.prdLi') as $foo){
echo $foo;
}
the output that i get is like this
<span>310.</span>
<span>Pepsi</span
.
.
.
but what i actually want to get is the code with the parent element td.like this:
<td rowspan="2" class="prdNo"><span>310.</span></td>
<td colspan="2" class="prdDe" rowspan="2"><span>Pepsi</span></td>
.
.
.
please help me
Since Simple HTML DOM Parser supports CSS like selectors, you can use 'tr.prdLi td' to specify all td elements which are children of tr with class prdLi. The following should provide what you are looking for:
$htmlstr = <<<EOD
<table>
<tbody>
<tr>
<td><table>
<tbody>
<tr class="prdLi">
<td rowspan="2" class="prdNo"><span>310.</span></td>
<td colspan="2" class="prdDe" rowspan="2"><span>Pepsi</span></td>
</tr>
<tr class="prdLi">
<td class="prdAc"><span> 1.5L</span></td>
<td><span> </span></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
EOD;
$html = str_get_html($htmlstr);
foreach ($html->find('tr.prdLi td') as $foo) {
echo $foo . "\n";
}
Note that find() is called on the main simple_html_dom-element. In your example, the result was already limited by a previous find().
What andy says is correct, but the css for direct child is > *, therefore:
foreach($html->find('tr.prdLi > *') as $foo){
echo $foo . "\n";
}
Hi I'm trying to parse a Wikipedia document in which there is a table called "infobox biota" with this structure. I'm trying to get the following table data and classes of the following characteristics
Kingdom:
Phylum:
Subphylum:
Class:
Order:
Family:
<table class="infobox biota" style="text-align: left; width: 200px; font-size: 100%">
<tbody><tr>
<th colspan="2" style="text-align: center; background-color: rgb(211,211,164)">Rabbit</th>
</tr>
<tr>
<td colspan="2" style="text-align: center"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Rabbit_in_montana.jpg/250px-Rabbit_in_montana.jpg" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Rabbit_in_montana.jpg/375px-Rabbit_in_montana.jpg 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Rabbit_in_montana.jpg/500px-Rabbit_in_montana.jpg 2x" height="222" width="250"></td>
</tr>
<tr>
<th colspan="2" style="text-align: center; background-color: rgb(211,211,164)">Scientific classification</th>
</tr>
<tr>
<td>Kingdom:</td>
<td><span class="kingdom" style="white-space:nowrap;">Animalia</span></td>
</tr>
<tr>
<td>Phylum:</td>
<td><span class="phylum" style="white-space:nowrap;">Chordata</span></td>
</tr>
<tr>
<td>Subphylum:</td>
<td><span class="subphylum" style="white-space:nowrap;">Vertebrata</span></td>
</tr>
<tr>
<td>Class:</td>
<td><span class="class" style="white-space:nowrap;">Mammalia</span></td>
</tr>
<tr>
<td>Order:</td>
<td><span class="order" style="white-space:nowrap;">Lagomorpha</span></td>
</tr>
<tr>
<td>Family:</td>
<td><span class="family" style="white-space:nowrap;">Leporidae<br>
<small>in part</small></span></td>
</tr>
<tr>
<th colspan="2" style="text-align: center; background-color: rgb(211,211,164)">Genera</th>
</tr>
<tr>
<td colspan="2" style="text-align: left">
<div>
<table style="background-color:transparent;table-layout:fixed;" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr valign="top">
<td>
<div style="margin-right:20px;">
<p><i>Pentalagus</i><br>
<i>Bunolagus</i><br>
<i>Nesolagus</i><br>
<i>Romerolagus</i></p>
</div>
</td>
<td>
<div style="margin-right: 20px;">
<p><i>Brachylagus</i><br>
<i>Sylvilagus</i><br>
<i>Oryctolagus</i><br>
<i>Poelagus</i></p>
</div>
</td>
</tr>
</tbody></table>
</div>
</td>
</tr>
</tbody></table>
Here is my attempt to parse and obtain the kingdom,phylum,subphylum,class,order and family of a rabbit with the table structure. However I get a the following Array ( [Kingdom:] => [Phylum:] => [Subphylum:] => [Class:] => [Order:] => [Family:] => [
Pentalagus
Bunolagus
Nesolagus
Romerolagus
] => )
it doesnt fill in the array with the data for the rabbit. also it give me a parse error in the line shown below, what can be wrong?
<?php
//require"mydb.php";
header('Content-type: text/html; charset=utf-8'); // this just makes sure encoding is right
include('simple_html_dom.php'); // the parser library
$html = file_get_html('http://en.wikipedia.org/wiki/Rabbit');
$table = $html->find('table.infobox');
$data = array();
foreach($table[0]->find('tr') as $row)
{
$td = $row->find('> td');
if (count($td) == 2)
{
$name = $td[0]->innertext;
$text = $td[1]->find('a')[0]->innertext; //PARSE ERROR IS GIVEN HERE, after the find('a')[0], taking off the array takes away the error but just me no results
$data[$name] = $text;
}
}
print_r($data);
?>
$text = $td[1]->find('a')[0]->innertext;
In this line you are dereferencing a function. This is only available in PHP 5.4 or later. Try this instead:
$td = $td[1]->find('a');
$text = $td[0]->innertext;
I'm grabbing the content from all the td's in this table with the class="job" using this.
$table01 = $salary->find('table.table01');
$rows = $table01[0]->find('td.job');
Then I'm using this to output it which works, but obviously only outputs it as plaintext, I need to do some more with it...
foreach($table01[0]->find('td.job') as $element) {
$jobs .= $element->plaintext . '<br />';
}
Ultimately I would like it outputted to this format. Notice the a href is using the job name and replacing spaces and / with a -.
<tr>
<td class="small"> Graphic Artist / Designer
$23,755 – $55,335 </td>
</tr>
<tr>
<td class="small"> Sales Associate<br />
$15,577 – $56,290 </td>
</tr>
<tr>
<td class="small"> Film / Video Editor<br />
$24,184 – $94,493 </td>
</tr>
Heres the table im scraping
<table cellpadding="0" cellspacing="0" border="0" class="table01">
<tr>
<td class="head">Test</td>
<td class="job">
Graphic Artist / Designer<br/>
$23,755 – $55,335
</td>
</tr>
<tr>
<td class="head">Test</td>
<td class="job">
Sales Associate<br/>
$15,577 – $56,290
</td>
</tr>
<tr>
<td class="head">Test</td>
<td class="job">
Film / Video Editor<br/>
$24,184 – $94,493
</td>
</tr>
</table>
may be better to use regexps
<?php
$html=file_get_contents('1.html');
$jobs='';
if(preg_match_all("/<tr>.*?<td.*?>.*?<\/td>.*?<td\sclass=\"job\">.*?<a.+?href=\"(.+?)\".+?>(.*?)<\/a>(.*?)<\/td>.*?<\/tr>/ims", $html, $res))
{
foreach($res[1] as $i=>$uri)
{
$uri=strtolower(urldecode($uri));
$uri=preg_replace("/_\/_/",'-',$uri);
$uri=preg_replace("/_/",'-',$uri);
$jobs.='<tr><td class="small"> '.$res[2][$i].''.$res[3][$i].'</td></tr>'."\n";
}
}
echo $jobs;
Hello I'm trying to update this scholarship application box. However when the year changed to 2013 it only displays scholarship applicant info from 2013. I'd like it to display info from 2012. I tried messing around with the date but I cant seem to figure it out. Any help would be greatly appreciated!
<?php
$appYear = date("Y").'-'.(date("Y")+1);
$sql = 'select * from sApplication where studentID = "'.$database->iPrep($_SESSION['ID']).'" AND appYear = "'.$appYear.'" LIMIT 1';
$appID = Scholarship::iFindSQL($sql);
$total = count($appID);
if ($total > 0)
{
$app = array_shift($appID);
}
else
{
$app = 0;
}
?>
<li id="item-2">
<div id="appStatus">
<h3>Application Status</h3>
<blockquote>
<?php if ($app->submitted == ('0000-00-00') || !isset($app->submitted)) { ?>
<table style="border:1px solid #000;" width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="50%"><strong>Scholarship<br /> 2013-2014</strong></td>
<td width="50" align="right"> <a style="font-size:16px;" href="welcome.php? app=Scholar">Apply Now</a></td>
</tr>
<tr>
<td><strong>Date Submitted</strong></td>
<td align="right"> </td>
</tr>
<tr>
<td><strong>References</strong></td>
<td align="right"> </td>
</tr>
<tr>
<td><strong>Decision</strong></td>
<td> </td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
<tr>
<td><strong>Scholarship 2012-2013</strong></td>
<td> </td>
</tr>
<tr>
<td><strong>Decision</strong></td>
<td> </td>
</tr>
</table>
<?php } else { ?>
<table style="border:1px solid #000;" width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="90%"><strong>Scholarship 2013-2014</strong></td>
<td width="10%" align="right"> </td>
</tr>
<tr>
<td><strong>Date Submitted</strong></td>
<td align="right"><?=dbOutDate($app->submitted)?></td>
</tr>
<tr>
<td><strong>References</strong> </td>
<td align="right"></td>
</tr>
<tr>
<td colspan="2">
<?php
$refs = Reference::iFindSQL("Select * from reference where appID = '".$app->ID."'");?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php foreach($refs as $ref) { ?>
<tr> <td> <small><?php if($ref->rType == 'Academic Reference'){ echo 'Academic/Artistic/Professional'; } else { echo 'Community Service'; } ?></small></td> <td align="right"><?=$ref->status?></td></tr>
<?php } ?>
</table>
</td>
</tr>
<tr>
<td><strong>Decision</strong></td>
<td align="right">
<?php
if ($app->complete == 'Approved') { echo 'Approved'; }
if ($app->complete == 'Declined') { echo 'Declined'; }
if ($app->complete == 'Pending') { echo 'Pending'; }
if ($app->complete == 'Incomplete') { echo 'Incomplete'; }
Remove the WHERE clause that limits the year. Use ORDER BY to sort by year, descending.
$sql = 'select * from sApplication
where studentID = "'.$database->iPrep($_SESSION['ID']).
'" ORDER BY appYear DESC LIMIT 1';