4

I want to show two tables side by side. My html showing the correct result but when i change the html to pdf using TCpdf then the tables dont sho side by side because float property is not supported in TCPDF. Kindly tell me how can i show the tables side by side using tcpdf. My html is as follows

  <table style="float:left">

  <tr>
 <td>  
  </td>
  </tr>

 </table>

  <table style="float"left">

   <tr>
 <td>
 </td>
   </tr>

  </table>
anila
  • 119
  • 2
  • 3
  • 8
  • `style="float"left"` should probably say `style="float:left"`. – Jakuje Mar 04 '17 at 22:19
  • Not working in this way. That was a typo :) – anila Mar 05 '17 at 09:05
  • Possible duplicate of [Why does TCPDF ignore my inline CSS?](http://stackoverflow.com/questions/11395171/why-does-tcpdf-ignore-my-inline-css) – Jakuje Mar 05 '17 at 09:08
  • You should really use formatting using Cells if you want such specific design. The CSS attribute `float` is not supported in TCPDF. – Jakuje Mar 05 '17 at 09:08

3 Answers3

9

One of the way is to take one table and inside that put two table in each td. So the output will be

side by side table tcpdf

<?php
require_once('tcpdf_include.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 048');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 048', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// 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 (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', 'B', 20);

// add a page
$pdf->AddPage();

$pdf->Write(0, 'Example of side by sideHTML tables', '', 0, 'L', true, 0, false, false, 0);

$pdf->SetFont('helvetica', '', 8);


$tbl='<table>
  <tr>
    <td>

      <table cellspacing="0" cellpadding="1" border="1" style="float:right;width:300px">
        <tr>
          <td>1</td>
          <td>2</td>
        </tr>
        <tr>
          <td>1</td>
          <td>2</td>
        </tr>

      </table>
    </td>
    <td>
      <table cellspacing="0" cellpadding="1" border="1" style="float:right;width:300px">
        <tr>
          <td>3</td>
          <td>4</td>
        </tr>
        <tr>
          <td>3</td>
          <td>4</td>
        </tr>

      </table>
    </td>
  </tr>
</table>

';


$pdf->writeHTML($tbl, true, false, false, false, '');

//Close and output PDF document
$pdf->Output('example_048.pdf', 'I');
?>
Deep 3015
  • 9,929
  • 5
  • 30
  • 54
0

Apparently, TCPDF has some issues regarding setting two divs or tables next to each other, and probably many other elements, so CSS won't do the trick. So forget about styling and floating and widthing(?), and set the tables inside another table, such as Deep 3015's answer. I'm not sure about this, but I'm certain that HTML2PDF implements plenty of CSS that's not available in TCPDF (which is good due to HTML2PDF being based on TCPDF), just saiyan.

0

Please use below code normal way very hard to do even though its not possible try my best

<table style="padding-top: 10px;">
<tr style="font-size:11px;">
    <td>
        <table border="1" cellpadding="1" cellspacing="0" style="width:100%">
            <tr>
                <th bgcolor="#BDD6EE" colspan="2"
                    style="height:20px; text-align: center;vertical-align: middle;"><strong>ADMISSION
                    PACKAGE 2019</strong>
                </th>
            </tr>
            <tr>
                <td style="width:80%; text-align: center;">Half of CEA License Fee</td>
                <td style="width:20%;text-align: center;">$115.00</td>
            </tr>
            <tr>
                <td style="text-align: center;">CEA Application Fee</td>
                <td style="text-align: center;">$53.50</td>
            </tr>
            <tr>
                <td style="text-align: center;">Professional Indemnity Premium (Blanket)</td>
                <td style="text-align: center;">$139.00</td>
            </tr>
            <tr>
                <td style="text-align: center;">Convention Package</td>
                <td style="text-align: center;">$128.00</td>
            </tr>
            <tr>
                <td style="text-align: center;">Estate Agent Card</td>
                <td style="text-align: center;">$20.00</td>
            </tr>
            <tr>
                <td style="text-align: right;"><b>TOTAL:</b>&nbsp;&nbsp;</td>
                <td style="text-align: center;"><b>$455.50</b></td>
            </tr>
        </table>
    </td>
    <td>
        <table border="1" cellpadding="1" cellspacing="0" style="width:100%">
            <tr>
                <th bgcolor="#BDD6EE" colspan="2"
                    style="height:20px; text-align: center;vertical-align: middle;"><strong>RENEWAL PACKAGE
                    2020</strong>
                </th>
            </tr>
            <tr>
                <td style="width:80%; text-align: center;">CEA License Fee</td>
                <td style="width:20%; text-align: center;">$230.00</td>
            </tr>
            <tr>
                <td style="text-align: center;">Professional Indemnity Premium (Blanket)</td>
                <td style="text-align: center;">$139.00</td>
            </tr>
            <tr>
                <td style="text-align: center;">Convention Package</td>
                <td style="text-align: center;">$128.00</td>
            </tr>
            <tr>
                <td style="text-align: right;"><b>TOTAL:</b>&nbsp;&nbsp;</td>
                <td style="text-align: center;"><b>$497.00</b></td>
            </tr>
        </table>
    </td>
</tr>

Uthaya
  • 363
  • 2
  • 15