Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCPDF issue showing two tables side by side

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>
like image 646
anila Avatar asked Oct 30 '25 01:10

anila


1 Answers

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');
?>
like image 116
Deep 3015 Avatar answered Nov 01 '25 09:11

Deep 3015



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!