TCPDF rendering issue - php

I am having an issue with tcpdf and rendering divs. Below is a cut down version of my code:
<?php
require_once (APP . 'vendors/xtcpdf.php');
ob_clean();
$tcpdf = new XTCPDF();
$tcpdf->AddPage();
$html = '<div style="width: 333px;height: 750px;float: left;border: 1px solid black;">
Col One Test
</div>
<div style="width: 333px;height: 750px;float: left;border: 1px solid black;">
Col Two Test
</div>
<div style="width: 333px;height: 750px;float: left;border: 1px solid black;">
Col Three Test
</div>';
$tcpdf->writeHTML($html, true, false, true, false, '');
echo $tcpdf->Output('test.pdf', 'D');
?>
The XTCPDF is simply just an extension to overwrite the header and footer so is irrelevant here as it is not used for now. The issue arises when putting this data into the PDF. Below is how the code renders when displayed in a webpage:
However when rendered in a PDF this is what I get:
Cheers,
Chris.

Related

HTML2PDF margin bug

I am currently using html2pdf to convert a document in my company to PHP, to be able to include my variables afterwards and save it as a pdf,
the problem is currently with my "div M1,M2,M3".
I make it align with "#M1,#M2,#M3{display: inline;}"
however I feel that my M2 "TEL:" is based on the top frame, rather than on the M1
$html = '<img src="logoTCSfinal.png" class="tcs" style="width:10%;margin-
left:20px;margin-right: 550px;">
<img src="ICSL.png" class="ics" style="width:10%;"><br>
<div style="width: 100%;padding-left:2px;padding-top:2px;font-weight: 600;padding-
bottom:2px;border: 3px solid #000000; text-align: left;">DEFINITION DES BESOINS</div>
<style>#M1,#M2,#M3{display: inline;}</style>
<div id="M1" style="padding-left:5px;padding-top: 10px;font-weight: 600;">SOCIETE:
</div>
<div id="M2" style="clear: both;font-weight: 600;">TEL:</div>
<div id="M3" style="font-weight: 600;">FAX:</div>';
$html2pdf = new Html2Pdf();
$html2pdf->writeHTML($html);
$html2pdf->output();
?>
but
however it displays it to me like
this

PHPOffice/PHPWord heading tag not display in Correct font sizes in word document

I am working in symfony PHPOffice/PHPWord document download application. I get document template from the database which has been created previously. for my sample testing I have used
<h1 style="text-align: left; background-color: #33cccc;">Heading 1</h1><h2 style="text-align: left; color: #00ff00; background-color: #ff00ff;">Heading 2</h2><h3 style="text-align: left;">heading 3</h3><h4 style="text-align: left;">heading 4</h4><h5 style="text-align: left;">heading 5</h5><h6 style="text-align: left;">heading 6</h6>
I pass the document content to;
public function getDocxBuilder(): PhpWord {
if (is_null($this->docxBuilder)) {
$this->docxBuilder = new PhpWord();
}
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
return $this->docxBuilder;
}
Html::addHtml($section, $content, false, false);
$objWriter = IOFactory::createWriter($this->docxBuilder, 'Word2007');
All above heading tags display in 14pt sizes in the downloaded document. why Heading tag font sizes not working,

PHP, Codeigniter, Dompdf: HTML generating fine but exectuion time out whlie rederning PDF

I have large amount of data that needs to be process and add as tables in PDF using Codeigniter. PDF contain some HTML elements, images, icons, and need lots of alignment using CSS.
So, to achieve this goal I did some search and checked which PDF generation plugin will be suitable for me. So, rather than selecting FPDF, TCPDF or HTMLTOPDF, mPDF etc. I chosen DOMPDF as it is supporting most of the css styles and it serves my purpose as well.
Initially, it was working fine as data was not much heavy and PDF with 10-20 pages was generating fine. But, as data gets increased and need to put about 35-45 pages in my PDF, system gets time out.
So, I changed server settings and made "4GB of RAM with 1 CPU to 8GB of RAM with 4 CPUs". And, increased max_execution_time to 90, memory_limit to 384M but still DOMPDF not rendering large PDFs having pages more than about 35.
I have set landscape mode to download PDF instead save it.
Below is the PHP code in my controller of Codeigniter.
$this->load->library('pdf');
$teaminfo=$this->pdf_model->getTeamName($teamid);
$data=array();
if($teaminfo != false)
{
$teamname=$teaminfo->team_name;
$data['teamname']=$teamname;
$formateddate=date('F j, Y');
$data['teammeetingdate']=$formateddate;
//add code to get and pass the terms and replacement array
$termsList=$this->getTermsArray($teamid);
$data['searchterms']=$termsList['searchterms'];
$data['replacement']=$termsList['replacement'];
//get teammeeting roster
$data['rosterlist']=$this->getRostertable($teamid);
$personwisedata=$this->getteammemberData($teamid);
$data['personwiseData']=$personwisedata;
$kmresponse=$this->get_last_six_month_keymetrics_details_by_userid_without_owner($teamid);
$data['noownerkmdata']=$kmresponse;
//set pdf title
$teamnametitle='My PDF Notes - '.$teamname.' '.date("m.d.Y");
$pdftitle=$teamnametitle.'.pdf';
$this->pdf->set_paper('a4', 'landscape');
$this->pdf->set_option( 'enable_font_subsetting' , true );
$this->pdf->load_view('backend/Pdf/teammeeting_pdf', $data);
$this->pdf->render();
$this->pdf->stream($pdftitle,array("Attachment" => 0));
}
For small size PDFs it is working fine. But, when long PDF need to generate execution stops and showing error "Internal Server Error" on page.
When I just print output on browser by putting exit, it works within a minute, but when I send that html to render on PDF and stream it, system stops execution.
I tried to set max_execution_time and memory_limit through htaccess and ini_set but it not helped me.
Hope so anyone will help me.
Dompdf very slow,please use tcpdf
https://tcpdf.org/examples/
very simple,
please check this
require_once APPPATH. 'third_party/TCPDF-master/tcpdf.php';
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//$pdf->SetFont('times', '', 10);// Font Name, Style, Size, Other file name
$pdf->SetFont('times', '', 12);
// Add a page
$pdf->AddPage();
// set text shadow effect
$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
$html ='
<style>
.invoice_font{
font-size:25px;
font-family: "Times New Roman", Times, serif;
}
.title img{
margin-top:20px;
}
.addFirst{
font-size:10px;
font-weight:bold;
font-family: "Times New Roman", Times, serif;
}
.addAnother{
font-size:10px;
font-family: "Times New Roman", Times, serif;
}
.invoice_sec_font
{
font-size:10px;
font-family: "Times New Roman", Times, serif;
}
.DescriptionDiv{
background-color:#3e3e3e;
color:#ffffff;
font-size:10px;
font-family: "Times New Roman", Times, serif;
}
.TermsConditionDiv{
font-size:10px;
font-family: "Times New Roman", Times, serif;
}
</style>
<table class="first" cellpadding="4" cellspacing="6" border="0">
<tr>
<td>
<h1 class="title"><img src="http://cloudnowtech.com/assets/img/cn_logo.png" style="width: 200px;height: 50px;"></h1>
<div>
<br/>
<span class="addFirst">CloudNow Technologies Pvt. Ltd.</span><br/>
<span class="addAnother">CIN - U74999TN2014PTC096441</span><br/>
<span class="addAnother">No. 61, Chamiers House, Chamiers Road, R.A Puram</span><br/>
<span class="addAnother">Chennai Tamil Nadu 600028</span><br/>
<span class="addAnother">India</span>
</div>
</td>
<td align="right"></td>
<td align="right">
<div class="test">
<span class="invoice_font">Invoice</span><br/>
<span>Invoice ID :';
$html .= 'INV-'.$this->session->userdata('ORDER_ID').'</span>
</div>
</td>
</tr>
<tr>
<td>
<div>
<br/>
<span class="addFirst">Bill To.</span><br/>
<span class="addAnother">';
$html .= $this->session->userdata('fname')." ".$this->session->userdata('lname').'</span><br/><span class="addAnother">';
$html .= $this->session->userdata('username').'</span><br/>';
$html .= '<span class="addAnother"></span><br/>
<span class="addAnother"></span>
</div>
</td>
<td align="right">
<div class="test"><br/>
<span class="invoice_sec_font">Invoice Date :</span><br/>
</div>
</td>
<td align="right">
<div class="test"><br/>
<span class="invoice_sec_font">';
$html .= date("d-M-Y").' </span><br/></div></td></tr></table>';
$html .= '<table class="secs" cellpadding="5" cellspacing="0" border="0">
<tr class="DescriptionDiv"><td>Number Of User</td> < <td align="right"> Amount </td></tr><tr><td>';
$html .= $this->session->userdata('new_users').'User</td><td align="right">';
$html .= $this->session->userdata('amount').'</td>
</tr><tr><td> </td><td> </td><td> </td>
</tr><tr><td></td> <td align="right"> Total </td> <td align="right">';
$html .= $this->session->userdata('amount').'</td></tr></table>';
$html .= "<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>";
$html .= '<table cellpadding="5" cellspacing="0" border="0" class="TermsConditionDiv">
<tr>
<td>Terms & Conditions No TDS has to be deducted on the payment of cloudNow Licenses. A declaration will be submitted
for the same. Please note that this estimate is just for reference.</td>
</tr>
</table>';
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
//$pdf->Output('example_025.pdf', 'I');
$DynamicNameofPic = rand(1000,10000)."_Invoice.pdf";
$FileNameDynamic = "path".$DynamicNameofPic;
$pdf->Output($FileNameDynamic,'F');

Fatal error: Class 'TCPDF' not found

I am generating the PDF file but facing the trouble. Can anybody tell me the solution of this error. Below is the code that I used for that. I include the tcpdf for this but there is a fatal error that saying that tcpdf file in not available or we can say not found.
<?php
$tcpdf_include_dirs = array(realpath('tcpdf.php'), '/usr/share/php/tcpdf/tcpdf.php', '/usr/share/tcpdf/tcpdf.php', '/usr/share/php-tcpdf/tcpdf.php', '/var/www/tcpdf/tcpdf.php', '/var/www/html/tcpdf/tcpdf.php', '/usr/local/apache2/htdocs/tcpdf/tcpdf.php');
foreach ($tcpdf_include_dirs as $tcpdf_include_path) {
if (#file_exists($tcpdf_include_path)) {
require_once($tcpdf_include_path);
break;
}
}
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // Create New PDF Doc
$pdf->SetCreator(PDF_CREATOR); //Setup a document information
include("db_connection.php");
$isql = mysqli_query($con, "SELECT * FROM `cpdf`") OR die("Data Select problem: ".mysqli_error($con));
$num = mysqli_num_rows($isql);
$pdf->AddPage(); //Add new page
while($row = mysqli_fetch_array($isql)){
$firstname = $row['fname'];
$lastname = $row['lname'];
$fullname = $firstname ." ".$lastname;
?>
<html>
<head>
<title>PDF Page</title>
</head>
<body>
<form>
<div>
<div><img style="width: 100%; height: 20%" src="image/FlZJRBAXRlweb design.idevtechnolabs.socialsigna.l.JPG"/></div>
<div style="width: 100%; height: 30%">
<table style="float: right; border: 2;">
<tr style="width: 10%;"><td style="text-align: left;"><?php echo $fullname; ?></td></tr>
<tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['add1']; ?></td></tr>
<tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['add2']; ?></td></tr>
<tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['city']; ?></td></tr>
<tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['state']; ?></td></tr>
<tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['date']; ?></td></tr>
</table>
</div>
<div style="float: left; height: 10%;">
<b>Subject:</b> <?php echo $row['subject']; ?>
</div>
<div style="height: 40%; width: 100%;">
<p style="text-align: justify;">Hey, <br /><br /> Mr. <?php echo $fullname; ?>. This is to inform you that a day after tomorrow is the last date of your invoice payment. This is a reminder notice to pay your <?php echo $row['bill']; ?> invoice amount our nearest store and takes advantage of our services.</p>
<p style="text-align: justify; text-indent: 4em;">We request you to pay your <?php echo $row['bill']; ?> Bill as soon as possible.</p>
<span style="float: right;">Thank you,<br /><img src="#"/></span>
</div><?php $pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);
}
$pdf->Output('example_002.pdf', 'I'); ?>
</div>
</form>
</body>
</html>
As a first step, comment out the first seven lines of code and add one new line of code that includes tcpdf.php using the full path to the file. If that doesn't work then you should check the contents of the tcpdf.php file to make sure that it hasn't been corrupted somewhere along the way. That is, make sure it still contains the code that declares the TCPDF class.
If that works then comment out the hard-coded include statement, uncomment the seven lines that were commented out earlier and add an echo statement to print out the $tcpdf_include_path variable during each iteration of that loop. As long as one of those paths match the hard-coded path that presumably worked earlier, then your code should work fine.
Finally, and I highly doubt this is the case, but if you happened to have a case-sensitive file system and you happened to have the tcpdf.php file saved as TCPDF.PHP, for example, then that might contribute to the problem. I'm only mentioning that possibility for completeness to the answer, but it is highly unlikely, especially based on the information you provided, that this is the problem in your case.

enable jquery slideToggle() work for multiple outputs that comes from a while

I have the following piece of code in php where I was trying to apply jquery slideToggle() for each youtube video presentation. My problem is that jquery slideToggle() works only for my first youtube video presentation inside my while statement. The rest of them are not working. Any idea how to fix this?
<style>
#flip
{
padding:0px;
}
#panel
{
width:475px;
margin-left:3px;
margin-bottom:5px;
padding:4px;
display:none;
box-shadow: 0 0 20px rgba(0, 30, 10, 2.8);
-webkit-box-shadow: 0 0 20px rgba(0, 10, 0, 2.8);
-moz-box-shadow: 0 0 20px rgba(0, 10, 0, 2.8);
background-color:#363636;
}
</style>
<script>
$(document).ready(function(){
$("#flip").click(function(){
$("#panel").slideToggle("slow");
});
});
</script>
<?php
// above code
//next starts the while and outputs from my table all rows that contains users posts
// my code outputs all youtube links in a presentation format
while(){
$row['comment'] = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", "</br>
<div id='panel'>
<object width=\"0px;\" height=\"0px;\">
<param name=\"movie\" value=\"http://www.youtube.com/v/$1&hl=en&fs=1\"></param>
<param name=\"allowFullScreen\" value=\"true\"></param>
<embed src=\"http://www.youtube.com/v/$1&hl=en&fs=1?&autoplay=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"475px;\" height=\"260px;\"></embed>
</object>
</div>
<table style='border:1px solid lightgrey;'>
<td bgcolor='#EBEBEB' style='vertical-align:top;'>
<div id='flip' style='cursor:pointer;'>
<div id='container'><div id='img1'><img src='http://img.youtube.com/vi/$1/default.jpg'/></div><div id='img2'><img src='img/play-button.png' style='width:40px; height:40px;'/> </div></div>
</div>
</td>
<td width='355px;' bgcolor='#EBEBEB' style='vertical-align:top;'>
<font color='#363636'><b>$video_title</b></font><font color='#545454'></br><a href='http://www.youtube.com/watch?v={$id}' target='_blank'><font color='#69aa35'><b>Youtube.com</b></font></a> - $video_perigrafh...</font><font color='#949494'>[$view_count views]</font>
</td>
</table>", $row['comment']);
}
?>
You are using an id (#panel) and id's are supposed to be unique. The selector is based on the native GetElementByID, which returns the first match.
You should use a class (<div class="panel">) instead.
http://jsfiddle.net/gLXLr/ - illustration of the id vs class targeting
Edit: regarding the new code with classes, if your HTML is:
<div class='panel'>
...
</div>
<table style='border:1px solid lightgrey;'>
<tr>
<td bgcolor='#EBEBEB' style='vertical-align:top;'>
<div class='flip' style='cursor:pointer;'>
..
</div>
</td>
</tr>
</table>
The code for the toggle should be:
$(document).ready(function(){
$(".flip").click(function() {
$(this).parents('table').prev('.panel').slideToggle("slow");
});
});
You can adjust it to fit your needs , of course.

Categories