TCPDF - HTML table align right inside writeHTMLCell does not work - php

I create a table with HTML to be inserted into TCPDF::writeHTMLCell with this format. The table only contains image.
$html_table ='<table align="right" border="1">
<tr>
<td width="10%" align="center">
<img src="http://localhost/img1.png" width="40" height="40" />
</td>
<td width="10%" align="center">
<img src="http://localhost/img2.png" width="40" height="40" />
</td>
</tr>
<tr>
<td width="10%" align="center">
<img src="http://localhost/img3.png" width="40" height="40" />
</td>
<td width="10%" align="center">
<img src="http://localhost/img4.png" width="40" height="40" />
</td>
</tr>
</table>';
Here's the TCPDF code to create HTMLCell
$pdf->writeHTMLCell(100, '', '', $pdf->getY(), $html_table, 1, 0, 0, false, 'R', false);
Even thought the HTML can show the table at the right side of page, TCPDF only shows this table at the left side inside the cell.
What is the right code to put the table in align right, put in the right side of the HTMLCell ?

Related

Resize width and height of images

I have content stored in mysql, as following:
<table width="450" cellspacing="1" cellpadding="1" border="1">
<tbody>
<tr>
<td><img width="513" height="680" align="left" alt=" src="/userfiles/image/pic.jpg" /></td>
<td><img width="315" height="700" align="left" alt=" src="/userfiles/image/DSC_0389.JPG" /></td>
<td><img width="580" height="320" align="left" alt=" src="/userfiles/image/ktxh.jpg" /></td>
</tr>
</tbody>
</table>
When I load from db, PHP and display in html by PHP, there is no problem.
Now, I want all images, be displayed by fixed width and height as 200 X 200 AND TABLE BORDER = '0'
<table width="200" cellspacing="1" cellpadding="1" border="0">
<tbody>
<tr>
<td><img width="200" height="200" align="left" alt=" src="/userfiles/image/pic.jpg" /></td>
<td><img width="200" height="200" align="left" alt=" src="/userfiles/image/DSC_0389.JPG" /></td>
<td><img width="200" height="200" align="left" alt=" src="/userfiles/image/ktxh.jpg" /></td>
</tr>
</tbody>
</table>
How do I solve this problem?
Replace with this code and css
<style>
.cstm
{
width:200px;
height:200px
}
table
{
border:0
}
</style>
<table width="200" cellspacing="1" cellpadding="1" border="0">
<tbody>
<tr>
<td><img class="cstm" align="left" alt=" src="/userfiles/image/pic.jpg" /></td>
<td><img class="cstm" align="left" alt=" src="/userfiles/image/DSC_0389.JPG" /></td>
<td><img class="cstm" align="left" alt=" src="/userfiles/image/ktxh.jpg" /></td>
</tr>
</tbody>
</table>
As you mention the $content is dynamic, can you try adding the style to the table as such:
<style>
table td>img
{
width:200px;
height:200px
}
</style>

While Loop in FPDF only prints 1 result

i'm having a problem with FPDF, i want to create a While Loop that returns every result that my SQL query does when i use Phpmyadmin, the problem here is that it only returns one. If i use
$pdf->Cell(190,10,''.$pdf_info2['format'].'',1,1,0);
it does print the result i want, but i need to return them in the table as i show below.
Ps: This is my firts question so i appolagise if i wasn't that clear o my problem.
Thanks in advance
$html='<table border="0">
<tr>
<td width="150" height="40" bgcolor="#e6e6e6">Tipo</td>
<td width="150" height="40" bgcolor="#e6e6e6">Formato</td>
<td width="150" height="40" bgcolor="#e6e6e6"> </td>
<td width="150" height="40" bgcolor="#e6e6e6">Pago</td>
<td width="150" height="40" bgcolor="#e6e6e6">Editar</td>
</tr>';
while($pdf_info2 = $smth->fetch(PDO::FETCH_ASSOC)) {
$html2 = '<tr>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">.$pdf_info['format'].</td>
<td width="150" height="40" bgcolor="#e6e6e6">.$pdf_info['format'].</td>
<td width="150" height="40" bgcolor="#e6e6e6">.$pdf_info['format'].</td>
<td width="150" height="40" bgcolor="#e6e6e6">.$pdf_info['format'].</td>
</tr>';
}
$pdf->WriteHTML($html);
$pdf->WriteHTML($html2);
Use this code:
First you must need to define before loop: $html2 = ''; and concatenate with $html2 .= in while loop see below code for updated code:
$html2 ='';
$html ='<table border="0">
<tr>
<td width="150" height="40" bgcolor="#e6e6e6">Tipo</td>
<td width="150" height="40" bgcolor="#e6e6e6">Formato</td>
<td width="150" height="40" bgcolor="#e6e6e6"> </td>
<td width="150" height="40" bgcolor="#e6e6e6">Pago</td>
<td width="150" height="40" bgcolor="#e6e6e6">Editar</td>
</tr>';
while($pdf_info2 = $smth->fetch(PDO::FETCH_ASSOC)) {
$html2 .='<tr>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
</tr>';
}
$pdf->WriteHTML($html);
$pdf->WriteHTML($html2);
**Option1.**first you need to merger data with previous data so use $html .= $html;
Option2 update $pdf_info
to
$pdf_info2
and no need to use 2 $pdf->WriteHTML();
so total code will be
$html='<table border="0">
<tr>
<td width="150" height="40" bgcolor="#e6e6e6">Tipo</td>
<td width="150" height="40" bgcolor="#e6e6e6">Formato</td>
<td width="150" height="40" bgcolor="#e6e6e6"> </td>
<td width="150" height="40" bgcolor="#e6e6e6">Pago</td>
<td width="150" height="40" bgcolor="#e6e6e6">Editar</td>
</tr>';
while($pdf_info2 = $smth->fetch(PDO::FETCH_ASSOC)) {
$html .= '<tr>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
</tr>';
}
$pdf->WriteHTML($html);

DataTable plugin not working with dynamically generated php data?

DataTable plugin not working with dynamically generated php data ?
I am using data table in to display a dynamic table. But its not working.
I tried to use static table its working I don't understand the problem
Here is my HTML Table and js script.
Can anyone solve the issue.
$(document).ready(function () {
$('#myTable').dataTable();
});
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" id="myTable">
<thead>
<tr>
<th width="100" height="30" align="left" bordercolor="#999999" bgcolor="#d3d3d3">Client Name</th>
<th width="100" height="30"align="left" bordercolor="#999999" bgcolor="#d3d3d3">EPIC ID</th>
<th width="100" height="30" align="left" bordercolor="#999999" bgcolor="#d3d3d3">Project Name</th>
<th width="100" height="30"align="left" bordercolor="#999999" bgcolor="#d3d3d3">Category</th>
<th width="100" height="30" align="left" bordercolor="#999999" bgcolor="#d3d3d3">Epic Status</th>
<th width="150" height="30" align="left" bordercolor="#999999" bgcolor="#d3d3d3">Total Estimated Hours</th>
<th width="150" height="30" align="left" bordercolor="#999999" bgcolor="#d3d3d3">Total Time Spent</th>
<th width="150" height="30" align="left" bordercolor="#999999" bgcolor="#d3d3d3" >% Hours Burned</th>
<th width="150" height="30" align="left" bordercolor="#000000" bgcolor="#d3d3d3">% Project Complete</th>
<th width="150" height="30" align="left" bordercolor="#000000" bgcolor="#d3d3d3">Action Status</th>
</tr>
</thead>
<tbody>
<tr <?php if($cnt%2==0){echo "bordercolor='#FFFFFF' bgcolor='#FFFFFF'";}else{echo "bordercolor='#999999' bgcolor='#FFFFFF'";}?>>
<td align="left" width="100" height="30"><?php echo "$ClientName";?></td>
<td align="left" width="100" height="30">
<?php
echo form_open('Riskreport',array('name'=>'s2frm'.$cnt,'target'=>'_blank'));?>
<?php echo "$EPICID";?>
<input type="hidden" name="epickeyid" value="<?php echo "$EPICID";?>" />
<?php echo $formbuild;?>
</form>
</td>
<td align="left" width="100" height="30"><?php echo "$ProjectName";?></td>
<td align="left" width="100" height="30"><?php echo "$Category";?></td>
<td align="left" width="100" height="30"><?php echo "$epic_status";?></td>
<td align="left" width="150" height="30"><?php echo "$TotalEstimatedHours";?></td>
<td align="left" width="150" height="30"><?php echo "$TotalTimeSpentinHours";?></td>
<td align="left" width="150" height="30" <?php if(($variance2>0)&&($variance2<=100)){echo "bgcolor='#92d050'";}else if(($variance2>100)&&($variance2<=120)){echo "bgcolor='#FFC200'";}else if($variance2>120){echo "bgcolor='#ff0000'";}else{echo "bgcolor='#FFFFFF'";}?>><?php echo $variance2prcnt;?></td>
<td align="left" width="150" height="30">
<?php
$PrjtCompleteprcnt=$ops1->getprjctdone($EPICID);
echo $PrjtCompleteprcnt;
?>
</td>
<td align="CENTER" width="150" height="30"><?php echo "$ActionStatus";?></td>
</tr>
</tbody>
</table>

how to add dynamic image to td background image?

in this code i want to add $image variable to td background but i dont know if add it between quotes without any problems..or delete quotes..and how to get it from youtube video..thanks for helping
<table width="130" height="97">
<tbody><tr>
<td valign="center" width="130" align="center" background="showvideo.php_files/2_003.jpg" height="97">
<a href="http://www.mysite.com/video/watch.php?VDCID=42608">
<img src="showvideo.php_files/play_arrow.gif" alt=" Theme Song " border="0">
</a>
</td>
</tr>
</tbody></table>
there you go:
<td valign="center" width="130" align="center" background="<?php echo $image; ?>" height="97"></td>

PHP Trying to get string from a table cell with regular expressions

I have the following site and I want with regular expressions to get the text between the following tags
<td colspan="2" align="left" valign="top" bgcolor="#FBFAF4"> ..... </td>
I am trying with the following however it returns an empty array of $matches.
preg_match_all("/<td(.*) bgcolor=\"#FBFAF4\"\>(.*)\<\/td>/",$old_filecontents,$matches);
Which is the correct pattern for this?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Exotiq - Ðñïúüíôá</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7"> <link href="Styles.css" rel="stylesheet" type="text/css"> <link href="stylesheets/Styles.css" rel="stylesheet" type="text/css"> <script src="scripts/PopBox.js" type="text/javascript"></script> <script type="text/javascript"> popBoxWaitImage.src = "images/spinner40.gif"; popBoxRevertImage = "images/magminus.gif"; popBoxPopImage = "images/magplus.gif"; </script> <script type="text/javascript"> AC_FL_RunContent('codebase', 'http://download.macromedia.com/pub/shockwave/ cabs/flash/swflash.cab#version=9,0,28,0', 'width','675','height','445','title','Morpork', 'src','assets/flash/morepork','loop', 'false','quality','high','pluginspage', 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash', 'wmode','transparent','movie','assets/flash/morepork'); </script> </head> <body background="images/fonto2.jpg" topmargin="0"> <table width="948" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><table width="948" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="24"> </td> <td height="150" colspan="3"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="900" height="150"> <param name="movie" value="flash/top02.swf"> <param name="quality" value="high"> <param name="wmode" value="transparent"> <embed src="flash/top02.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="900" height="150"></embed></object></td> <td width="24" height="150"> </td> </tr> <tr> <td height="31" colspan="5" valign="middle"> <div align="center"> <script src="menu/xaramenu.js"></script> <script Webstyle4 src="menu/menu_.js"></script> </div></td> </tr> <tr> <td width="24"> </td> <td width="200" valign="top" background="images/GreenFasa.jpg"> <br> <table width="180" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td height="25" class="styles"> Makuti<br> <hr> </td> </tr> <tr> <td height="25" class="styles"> Fun Palm<br> <hr> </td> </tr> <tr> <td height="25" class="styles"> Alang-Alang<br> <hr> </td> </tr> <tr> <td height="25" class="styles"> Thatch<br> <hr> </td> </tr> <tr> <td height="25" class="styles"> <strong>Abaca</strong><br> <hr> </td> </tr> <tr> <td height="25" class="styles"> </td> </tr> </table></td> <td colspan="2" align="left" valign="top" bgcolor="#FBFAF4"> <div align="left"> <table width="680" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="600" height="40" class="titles">ÊáôáóêåõÝò - ÏìðñÝëåò - Abaca</td> <td width="50" align="right" valign="middle" class="titles"> <div align="right"><img src="images/uk-flag.jpg" width="30" height="17" border="0"></div></td> </tr> <tr> <td colspan="2" class="body"><p>Ç ïìðñÝëá <strong>Abaca</strong> Ýñ÷åôáé ùò Üîéïò áíôéêáôáóôÜôçò ôçò ïìðñÝëáò Rattan ðïõ åðß 15 ÷ñüíéá óôïëßæåé ôéò åëëçíéêÝò ðáñáëßåò. Ôï <strong>Abaca</strong> åßíáé Ýíá öõóéêü õëéêü ðéï <strong>áíèåêôéêü</strong> êáé ðéï üìïñöï áðü ôï Rattan. <br> Ðáñáäßäåôáé ìå <strong>îýëéíï êïñìü åìðïôéóìïý</strong> Ö8åê.<br> <br> </p> <table width="680" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="340" height="150" valign="middle"> <div align="left"><img src="images/Manufactures/Umbrelas/Abaca/AbacaUmbrela.jpg" width="328" height="500"></div></td> <td width="340" height="150" valign="bottom" class="body"> <table width="340" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="170" height="130"> <div align="center"><img src="images/Manufactures/Umbrelas/Abaca/1_Abaca02_s.jpg" width="152" height="101" class="PopBoxImageSmall" onclick="Pop (this,50,'PopBoxImageLarge');" title="ÌåãÝèõíóç" pbsrc="images/Manufactures/Umbrelas/Abaca/1_Abaca02.jpg" pbCaption="Abaca - ÏìðñÝëá ðáñáëßáò" popBoxCaptionBelow="true" /></div></td> <td width="170" height="130"> <div align="center"><img src="images/Manufactures/Umbrelas/Abaca/2_Abaca03_s.jpg" width="150" height="112" class="PopBoxImageSmall" onclick="Pop (this,50,'PopBoxImageLarge');" title="ÌåãÝèõíóç" pbsrc="images/Manufactures/Umbrelas/Abaca/2_Abaca03.jpg" pbCaption="Abaca - ÏìðñÝëá ðáñáëßáò" popBoxCaptionBelow="true" /></div></td> </tr> <tr> <td width="170" height="130"> <div align="center"><img src="images/Manufactures/Umbrelas/Abaca/3_Abaca01_s.jpg" width="150" height="112" class="PopBoxImageSmall" onclick="Pop (this,50,'PopBoxImageLarge');" title="ÌåãÝèõíóç" pbsrc="images/Manufactures/Umbrelas/Abaca/3_Abaca01.jpg" pbCaption="Abaca - ÏìðñÝëá ðáñáëßáò" popBoxCaptionBelow="true" /></div></td> <td width="170" height="130"> <div align="center"></div></td> </tr> <tr> <td width="170" height="130"> <div align="center"></div></td> <td width="170" height="130"> <div align="center"></div></td> </tr> <tr> <td width="170" height="130"> <div align="center"></div></td> <td width="170" height="130"> <div align="center"></div></td> </tr> </table></td> </tr> <tr> <td width="340" height="50" valign="top"> <p align="center"> </p></td> <td width="340" height="50" valign="top"> <div align="center" class="perigrafes">ÊëéêÜñåôáé ðÜíù óôéò öùôïãñáößåò ãéá ìåãÝèõíóç</div></td> </tr> <tr> <td width="340" valign="bottom"> <div align="center"> </div></td> <td width="340" valign="bottom"> <p align="center"> </p></td> </tr> <tr> <td width="340" valign="top"> <div align="center"></div></td> <td width="340" valign="top"> <p align="center"> </p></td> </tr> <tr> <td height="20" colspan="2" valign="top"> </td> </tr> </table></td> </tr> </table> <font color="#FFFFFF"></font></div></td> <td width="24" height="420"> </td> </tr> <tr> <td width="24"> </td> <td width="200"> </td> <td width="600"> </td> <td width="100"> </td> <td width="24"> </td> </tr> </table></td> </tr> <tr> <td height="22"><table width="900" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#007F3E"> <tr> <td height="25"> <div align="center" class="styles">All rights reserved ® Designed by CONTINENTAL ADVERTISING </div></td> </tr> </table></td> </tr> </table> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-12742174-1"); pageTracker._trackPageview(); } catch(err) {}</script> </body> </html>
Given that the cell you're talking about contains HTML, another table in fact, you can't do traditional termination checking ... or you'll get the content between the cell opening and the first </td> you find. Plus '.' isn't multi-line friendly, so unless your cell opens and terminates on the same line, you'll get no matches.
I'd say don't use regular expressions for this. Try an XML parser.
If you were just getting plain text, that'd be fine, but because you're returning HTML which contains your terminator, you'll need to use a parser with some kind of DOM depth awareness ... ... or find a way to count terminators in regex.

Categories