2017-03-04 61 views
0

我想並排顯示兩個表。我的html顯示正確的結果,但是當我使用TCpdf將html更改爲pdf時,表格不併肩並行,因爲TCPDF中不支持float屬性。請告訴我如何使用tcpdf並排顯示錶格。我的html如下並排顯示兩個表的TCPDF問題

<table style="float:left"> 

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

</table> 

    <table style="float"left"> 

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

    </table> 
+0

'風格=「浮動」左「'或許應該說'風格=」浮動:左「' – Jakuje

+0

這樣不工作這是一個錯字。: ) – anila

+0

[爲什麼TCPDF忽略我的內聯CSS?](http://stackoverflow.com/questions/11395171/why-does-tcpdf-ignore-my-inline-css) – Jakuje

回答

0

其中一種方法是採取一張桌子和裏面,每個td放兩張桌子。所以輸出將是

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'); 
?>