PHP - Tcpdf And Table Cell Widths
Similar TutorialsHi I have used TCPDF to generate documents with single values from a mysql table. Now I want to generate a calendar. I have a table events_pbw which contains (amongst others) the fields id, date and name. I would like to generate a pdf which lists all of the results for entries after a particular date (eg Jan 1st) I have this: // get data from events_pbw table $result = mysql_query("SELECT id, date, name FROM events_pbw WHERE `date` > 2011-01-01" "); while($row = mysql_fetch_array($result)) { $appid = $row['id']; $date = $row['date']; $name = $row['name']; } But I don't know how to get the full list of results into the pdf. I'm sure this is very easy but I'm not great on php coding! Does anyone have any examples or help they could give me? Many thanks Hi I have a table (applicant) and I am looking at producing a pdf displaying various items of data from this table. I have succeeded in getting the look I want but in my query I use a fixed applicantid (in this case an id of 4). What I want to be able to do is to have the id cary according to the url. In other words, when someone comes from one web page to this one and the url is of the format .../pdf_production.php?applicantid=42. I'm not sure I've explained that very well but I hope someone can help - I think this is the last thing I need to sort out. Many thanks in advance. The code I have so far is: <?php require_once('../Connections/process.php'); ?> <?php require_once('../tcpdf/config/lang/eng.php'); require_once('../tcpdf/tcpdf.php'); // get data from users table mysql_select_db($database_process, $process); $result = mysql_query("SELECT * FROM applicant WHERE applicantid = '4'"); while($row = mysql_fetch_array($result)) { $appid = $row['applicantid']; $idcode = $row['idcode']; $type = $row['type']; $company = $row['company']; $email = $row['email']; } // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $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); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // --------------------------------------------------------- // set font $pdf->SetFont('dejavusans', '', 10); // add a page $pdf->AddPage(); // create some HTML content $txt = <<<EOD Below are the details I require Company type: $type Company Name: $company Company email: $email EOD; // output the HTML content // $pdf->writeHTML($htmlcontent, true, 0, true, 0); $pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0); // $pdf->writeHTML($inlinecss, true, 0, true, 0); // reset pointer to the last page // $pdf->lastPage(); //Close and output PDF document $pdf->Output('example_006.pdf', 'I'); //============================================================+ // END OF FILE //============================================================+ ?> I am trying to set the column widths in my HTML 5 script, but what ever I do the widths stay the same?
I found that the <col width=""> tag does not work in HTML 5.
So I tried <th style="width:130px">Week #</th> and this did not work.
I have also created a special table div style #table1.
Nothing changes when I make these changes!
Here is the table part of my script: <div id="table1"> <table width="250%" cellspacing="1" border="1" BGCOLOR="white"> <tr> <th style="width:130px">Week #</th> <th style="width:80px">18</th> <th style="width:80px">19</th> <th style="width:80px">20</th> <th style="width:80px">21</th> <th style="width:80px">22</th> <th style="width:80px">23</th> <th style="width:80px">24</th> <th style="width:80px">25</th> <th style="width:80px">26</th> </tr> <tr> <td>Visits</td> <td>300</td><td>346</td><td>266</td><td>216</td><td>339</td><td>288</td><td>231</td><td>213</td><td></td></tr> <tr> <td>From</td> <td>28/04/2014</td><td>05/05/2014</td><td>12/05/2014</td><td>19/05/2014</td><td>26/05/2014</td><td>02/06/2014</td><td>09/06/2014</td><td>16/06/2014</td><td>23/06/2014</td> </tr> <tr> <td>To</td> <td>04/05/2014</td><td>11/05/2014</td><td>18/05/2014</td><td>25/05/2014</td><td>01/06/2014</td><td>08/06/2014</td><td>15/06/2014</td><td>22/06/2014</td><td>29/06/2014</td> </tr> <tr> <td>USA</td><td>161</td><td>158</td><td>148</td><td>79</td><td>132</td><td>105</td><td>81</td><td>70</td><td></td> etc......... </table> </div>here is my style.css script: /* Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License */ body { margin: 0; padding: 0; background: #F1F1F1 url(images/img01.gif) repeat-x left top; font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: black; } quote { font-size:medium; } h1, h2, h3 { margin: 0; padding: 0; font-weight: normal; color: #023848; } h1 { font-size: 4em; } h2 { font-size: 2.4em; } h3 { font-size: 1.6em; } p, ul, ol { margin-top: 0; line-height: 180%; } ul, ol { font-size:large; } ul.a { list-style-type:circle; } ul.b { list-style-type:square; } ol.c { list-style-type:upper-roman; } ol.d { list-style-type:lower-alpha; } a { text-decoration: none; color: #4486C7; } p { font-size:large; } a:hover { } #wrapper { width: 980px; margin: 0 auto; padding: 0; } /* Header */ #header { width: 980px; height: 280px; margin: 0 auto; padding: 0px; background: url(images/head!.png) no-repeat left top; } /* Logo */ #logo { float: right; margin: 0; padding: 0; } #logo h1, #logo p { margin: 0; padding: 10px; } #logo h1 { float: left; padding-top: 223px; letter-spacing: -1px; text-align: right; text-transform: capitalize; font-size: 3.8em; color: purple; } #logo p { float: left; margin: 0; padding: 250px 0 0 10px; font: normal 20px Arial, Helvetica, sans-serif; font-style: italic; color: purple; } #logo a { border: none; background: none; text-decoration: none; color: black; } /* Search */ #search { float: right; width: 280px; height: 60px; padding: 20px 0px 0px 0px; background: #E2E2E2; border-bottom: 4px solid #FFFFFF; } #search form { height: 41px; margin: 0; padding: 10px 0 0 20px; } #search fieldset { margin: 0; padding: 0; border: none; } #search-text { width: 170px; padding: 6px 5px 2px 5px; border: 1px solid #DEDEDE; background: #FFFFFF; text-transform: lowercase; font: normal 11px Arial, Helvetica, sans-serif; color: #5D781D; } #search-submit { width: 50px; height: 22px; border: none; background: #B9B9B9; color: #000000; } /* Menu */ #menu { width: 980px; height: 90px; margin: 0 auto; padding: 0; } #menu ul { margin: 0; padding: 50px 0px 0px 0px; list-style: none; line-height: normal; } #menu li { float: left; } #menu a { display: block; width: 100px; height: 30px; margin-right: 1px; padding: 9px 0px 0px 0px; background: url(images/img02.gif) no-repeat left top; text-decoration: none; text-align: center; font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; color: #FFFFFF; border: none; } #menu a:hover, #menu .current_page_item a { text-decoration: none; } #menu .current_page_item a { padding-left: 0; } /* Page */ #page { width: 940px; margin: 0 auto; padding: 0px 0px 0px 40px; background: url(images/img03.gif) repeat-y left top; } #page-bgtop { padding: 20px 0px; } #page-bgbtm { } /* Content */ #content { float: left; width: 580px; padding: 30px 0px 0px 0px; } .post { background: url(images/img07.gif) no-repeat left 50px; margin-bottom: 15px; } .post-bgtop { } .post-bgbtm { } .post .title { height: 38px; margin-bottom: 10px; padding: 12px 0 0 0px; letter-spacing: -.5px; color: #000000; } .post .title a { color: #023848; border: none; } .post .meta { margin-bottom: 30px; padding: 5px 0px 15px 0px; text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; } .post .meta .date { float: left; } .post .meta .posted { float: right; } .post .meta a { } .post .entry { background: url(images/img08.gif) no-repeat left top; padding: 0px 0px 20px 0px; padding-bottom: 20px; text-align: justify; } .links { padding-top: 20px; font-size: 12px; font-weight: bold; } /* Sidebar */ #sidebar { float: right; width: 280px; margin: 0px; padding: 0px 20px 0px 0px; color: lightgray; } #sidebar ul { margin: 0; padding: 0; } #sidebar li { margin: 0; padding: 0; } #sidebar li ul { margin: 0px 0px; padding-bottom: 30px; } #sidebar li li { line-height: 35px; border-bottom: 1px dashed #D1D1D1; margin: 0px 30px; border-left: none; } #sidebar li li span { display: block; margin-top: -20px; padding: 0; font-size: 11px; font-style: italic; } #sidebar h2 { height: 38px; padding-left: 30px; letter-spacing: -.5px; font-size: 1.8em; } #sidebar p { margin: 0 0px; padding: 0px 30px 20px 30px; text-align: justify; } #sidebar a { border: none; } #sidebar a:hover { text-decoration: underline; color: #8A8A8A; } /* Calendar */ #calendar { } #calendar_wrap { padding: 20px; } #calendar table { width: 100%; } #calendar tbody td { text-align: center; } #calendar #next { text-align: right; } #dtable { font-size:small; color:black; } #dtable>h1 { background: #F1F1F1; } #table { font-size:small; color:black; text-align:center; width:200px; } #table1 { font-size:small; color:black; text-align:center; width:200px; border: 1px solid black; table-layout: fixed; } th, td { border: 1px solid black; overflow:hidden; width: 100px; } /* Footer */ #footer { height: 50px; margin: 0 auto; padding: 0px 0 15px 0; background: #ECECEC; border-top: 1px solid #DEDEDE; font-family: Arial, Helvetica, sans-serif; } #footer p { margin: 0; padding-top: 20px; line-height: normal; font-size: 9px; text-transform: uppercase; text-align: center; color: #A0A0A0; } #footer a { color: #8A8A8A; }I am completely baffled as to why the widths of the columns does not change when I try to fix the widths. They are all the same size? Please enlighten me where I am going wrong? This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=355480.0 I am having a problem trying to show if cell is empty echo one thing if empty and starttime if there is one: Code: [Select] if(isset($rown['starttime'])) { echo "Add Day"; } else { echo $rown['starttime']; } This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=314271.0 how to format only one specific row based on the value of one cell in a row? $result = mysql_query(select bal, etc. etc ..query ) while($row = mysql_fetch_assoc($result)) echo "<tr>"; echo "<td>" . $row['Account'] . "</td>"; echo "<td>" . $row['licence'] . "</td>"; echo "<td>" . $row['own'] . "</td>"; echo "<td>" . $row['bal'] . "</td>"; echo "</tr>"; Would appreciate help on how to format only the $row['bal'] output to red colour IF bal >5000 Thanks Trying to run this function so it displays the generated image in a table cell - Code: [Select] <?php function imgsecuregen($size = 6){ $width = 11*$size; $height = 25; $string = ""; for($i = 1; $i <= $size; $i++){ $string .= rand (0,9).""; } // for $im = ImageCreate($width, $height); $bg = imagecolorallocate($im, 102, 102, 102); // background $black = imagecolorallocate($im, 0, 255, 0); // text $grey = imagecolorallocate($im, 102, 102, 102); // border imagerectangle($im,0, 0, $width-1, $height-1, $grey); imagestring($im, 5, $size, 5, $string, $black); imagepng($im); imagedestroy($im); } imgsecuregen(8); // string length ?> Works if I load it directly, but not in a <td>. I am trying to insert data from a mysql in a table. I want the data to appear with the image on the left, item name on the top right followed by description underneath. <?php $sql = 'SELECT * FROM tbl_products ORDER BY id'; $result = $db->query($sql); $output[] = '<ul>'; $output[] = '<table border="3" bordercolor="#000000">'; while ($row = $result->fetch()) { $output[] = '<tr>'; $output[] = '<td><img src="images/'.$row['pic'].'" width="67" height="100" /></td>'; $output[] = '<td class="style10"><strong>'.$row['item_name'].'</strong></td>'; $output[] = '<td>'.$row['item_description'].'</td>'; $output[] = '</tr>'; } $output[] = '</table>'; echo join('',$output); ?> I would like the items to appear the same way as this page http://aafcollection.info/items/list.php This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=307147.0 Hi guys i have another question about my shopping cart.
I have in my sql database table called products. It consist of 4 columns (product_id, description, quantity, price).
Now on my index page, I want to call just one product from cell, which would have special price. But i don't know how to call one single product.
So my code looks like that:
<?php $sql="SELECT product_id FROM Products"; $query=mysql_query($sql); $row=mysql_fetch_array($query); ?><table > <tr><img src="Images/Image.jpg" width="380" height="300" /> </tr> <tr> <td><a href="index.php?page=index&action=add&id=<?php echo $row['product_id']?>">Add to cart</a></td> </tr> <?php ?> </table>This code display me first product but i would like to call 3 product how would i do that, so i have 6 products and i would like to call product N.3 to my index page. My code calls the first one, how would it call the third. Hi I have a table that populated by a recordset, and wondered whether is was possible to make a row background colour = red where a particular cell = some text? I have been searching around and not managed to find anything of use. Any help would be appreciated. Image name will come from database. It can be displayed in divs or table cells. Which is better using divs or table cells? Can anyone post sample code? http://img28.imageshack.us/i/44233003.png/
When I echo out my variable in the php file it works fine but when I put the variable in a table cell it doesn't echo out. I have a stdClass Object array with nested User arrays as a value that I would like to display in a table cell. I am struggling and have exhausted a lot of time. I am hoping to get a shove in the right direction if possible. The image below will show what I am trying to do.
$someArray = json_decode($token_result); foreach ($someArray as $key => $value) { $combined[] = "<tr><td>" . $value->customer . "</td><td>" . $value->city . '</td> <td>' . $value->state . "</td><td>" . $value->zipcode . '</td> <td>' . $value->totalUsers . "</td><td>" . $value->totalActiveUsers . "</td><td>" . $value->totalInActiveUsers . '</td><td> <a href="">' . $value->users . "</a></td></tr>"; } foreach ($combined as $value) { print $value; } Here is what my Array and Objects look like Array ( [0] => stdClass Object ( [customer] => SWSH [city] => Thomasville [state] => GA [zipcode] => 31792 [totalUsers] => 6 [totalActiveUsers] => 6 [totalInActiveUsers] => 0 [users] => Array ( [0] => stdClass Object ( [firstName] => xxx [lastName] => xxx [phoneNumber] => [userName] => cb_igwrth@xxx.com [createdBy] => [isActive] => 1 ) [1] => stdClass Object ( [firstName] => Dan [lastName] => Stewart [phoneNumber] => +11111111111 [userName] => dan.sxx@xxx.ga.gov [createdBy] => kwilliams@xxx.com [isActive] => 1 ) ) ) [1] => stdClass Object ( [customer] => xxxx [city] => Carver [state] => MA [zipcode] => 02330 [totalUsers] => 3 [totalActiveUsers] => 3 [totalInActiveUsers] => 0 [users] => Array ( [0] => stdClass Object ( [firstName] => Leo [lastName] => Furtado [phoneNumber] => 781-000-0000 [userName] => LFurtado@xxx.com [createdBy] => TConger@ccccc.com [isActive] => 1 ) ) ) ) Table is attached
I wanted to do auto numbering for my tables with css using TCPDF. I tried both ways but it does not work at all. I tried the one in the documentation of tcpdf and it does not work too. Can anyone give me a piece of advice on how to make this work? These are the both ways i mentioned and it did not work. $htmlcontent .=' <style> table { counter-reset: rowNumber; } table tr::before { display: table-cell; counter-increment: rowNumber; content: counter(rowNumber) "."; padding-right: 0.3em; text-align: right; } </style> <table id="receiptTable" cellpadding="3" style="max-height: 1000px;"> <tr> <td width = "7%"style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> </td> <td colspan="3" style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['product_title'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['product_sku'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['quantity'].' '.$irow['quantity_unit'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> RM '.$irow['product_buy_price'].' </td> <td width= "20%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> RM '.$irow['purchase_price'].' </td> </tr> </table> '; }
for this i use the method of including external css into my tables but it does not work as well. I did make sure my file path is correct. (the code below) $htmlcontent .=' <style>.file_get_contents(css/receipt.css).</style> <table id="receiptTable" cellpadding="3" style="max-height: 1000px;"> <tr> <td width = "7%"style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> </td> <td colspan="3" style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['product_title'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['product_sku'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['quantity'].' '.$irow['quantity_unit'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> RM '.$irow['product_buy_price'].' </td> <td width= "20%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> RM '.$irow['purchase_price'].' </td> </tr> </table> '; }
Hi I am trying to work out how to add a loop statement to my pdf generation (I think that's what I need). I have a mysql table - events with 3 fields - id, name and date. In my php page which is to generate the pdf I have: mysql_select_db($database_events, $events); $result = mysql_query("SELECT id, date, name FROM events_pbw WHERE id>200 "); while($row = mysql_fetch_array($result)) { $id = $row['id']; $date = $row['date']; $name = $row['name']; } and in amongst the $html part of the page I have: $html ="<html> $id<br> $name<br> $date<br> <i>This is a test calendar.</i> This all works fine but (obviously) just gives one result. What do I need to add to make it list out all of the possible events? Many thanks in advance. Hi I am trying to add an image to a pdf file created using tcpdf. Part of the code I have to date is: $pdf->AddPage(); // create some HTML content $htmlcontent = "<html> <strong>THIS IS AN EXAMPLE TITLE<br></strong> <p> This just some straight text that I've added to see what happens This just some straight text that I've added to see what happens This just some straight text that I've added to see what happens This just some straight text that I've added to see what happens This just some straight text that I've added to see what happens </p> <ol> <li>This is some example text for testing. <br> </li> <li>This is some example text for testing.</li> </ol> "; // output the HTML content $pdf->writeHTML($htmlcontent, true, 0, true, 0, ''); I have a logo which is in a folder and can be found at ../img/logo.png What I would like to do is have the image in the centre of the page before all of the text but whatever I've tried has failed. Any suggestions/answers would be much appreciated. Also I've failed at centering the title - any ideas on that. Many thanks. I want to produce a pdf document using mysql and TCPDF. I can do this OK in some circumstances but I now have a problem. I have two tables - documents and parties - they are linked by a common field docid. I have for table documents, the fields: docid, doctitle, idcode and for the parties table: partyid, docid, party (the field party is the name of the party) For any document there could be any number of parties and for a single idcode there could be any number of documents. For example, for idcode = 12345 there might be 2 documents called doctitle 1 and doctitle 2. For doctitle 1 there are 3 parties to it party1, party 2 and party 3. For doctitle 2 there are two parties - party4 and party 5. For any idcode (which is passed through by the url) I want the pdf to give a list such as: Doctitle 1: party name 1 party name 2 party name 3 Doctitle 2: party name 4 party name 5 Part of my code is: mysql_select_db($database_process, $process); $result2 = mysql_query("SELECT parties.docid, GROUP_CONCAT(party SEPARATOR '<br>') AS partylist, documents.doctitle FROM parties INNER JOIN documents ON parties.docid=documents.docid WHERE parties.idcode = '$appidpassed' GROUP BY parties.docid LIMIT 1 ") or die(mysql_error()); while($row = mysql_fetch_array($result2)) { $doctitle = $row['doctitle']; $parties = $row['partylist']; } and then further down the page: $doctitle<br> $parties This only gives one document and the parties associated with it. I know the solution is probably easy but I can't see it. Does anyone have any ideas? Hi,
I'm using TCPDF to create a PDF from a webpage.
This works great but I have the following problem:
I'm building in WordPress and as you may know WP saves images on different sizes. (e.g. 150x150, 300x300 and 1024x1024)
The thing I'm trying to create is that users can download a PDF ready for printing. So High Resolution images.
I use a preg_match_all function to match the image source and remove the additional image size from the filename so the original high resolution image is loaded.
e.g. image-150x150.jpg will be replaced by image.jpg.
So now the original image that has a image size of 6024x6024px and 300 DPI is loaded.
Then TCPDF uses a resize function that resizes the image back to 150x150 px but sets the DPI to 300 so it can be printed on a good quality.
This all works but now the problem comes:
If I do the preg_match_all function the image gets "pulled" from the rest of the content and looses it's position.
So my thought to fix this was. Get a preg_replace function and replace the image tag with a function that executes the whole image change like described above.
This doesn't work......
So i'm stuck here. Hope anyone can assist me with this.
Here is what I have done so far.
function execute(){ preg_match_all("/<img[^>]+src=(?:\"|\')\K(.[^\">]+?)(?=\"|\')/",$content,$matches,PREG_PATTERN_ORDER); for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) { $search = array('-'.$s1.'x'.$s2.'', '-'.$s3.'x'.$s4.'', '-'.$s5.'x'.$s6.''); $replace = array('', '', ''); $a = $matches[1][$i]; if (strpos($a,'-'.$s1.'x'.$s2.'') !== false) { $w = $s1; $w = $pdf->pixelsToUnits($w); $h = $s2; $h = $pdf->pixelsToUnits($h); $l = '57'; $l = $pdf->pixelsToUnits($l); $t = '170'; $t = $pdf->pixelsToUnits($t); }elseif (strpos($a,'-'.$s3.'x'.$s4.'') !== false) { $w = $s3; $w = $pdf->pixelsToUnits($w); $h = $s4; $h = $pdf->pixelsToUnits($h); $l = '217'; $l = $pdf->pixelsToUnits($l); $t = '20'; $t = $pdf->pixelsToUnits($t); }elseif (strpos($a,'-'.$s5.'x'.$s6.'') !== false) { $w = $s5; $w = $pdf->pixelsToUnits($w); $h = $s6; $h = $pdf->pixelsToUnits($h); $l = '57'; $l = $pdf->pixelsToUnits($l); $t = '310'; $t = $pdf->pixelsToUnits($t); } $content .= $pdf->Image(str_replace($search,$replace,$matches[1][$i]), $l, $t, $w, $h, 'JPG', '', '', true, 300, '', false, false, 0, false, false, false); } }; global $post; $id = $_GET['id']; $content_post = get_post($id);// get the content $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $content = preg_replace('/<img[^>]+./e',execute(), $content); // replace the image tag with the new image // EXPORT IT ALL $pdf->writeHTML($content, true, false, true, false, ''); |