2011-11-24 60 views
3

我正在嘗試使用HTML代碼使用TCPDF製作PDF文檔。與TCPDF位置h1,h2,h3和其他標記

目前我使用此代碼:

// set font 
$pdf->SetFont('dejavusans', '', 36); 

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

$html = ' 
<style> 
.h1 { 
color: #2B6999; 
font-weight: normal; 
} 

</style> 

<h1 class="h1">Test</h1> 

'; 

// output the HTML content 
$pdf->writeHTML($html, true, false, true, false, 'C'); 

我怎麼能這樣定位文本?我不能使用標籤邊距等。

任何人都可以幫我解決這個問題嗎?

回答

0

您正在使用writeHTML,它完全超出了HTML,您需要使用「$pdf->Cell」函數。有很多例子在這個位置http://www.tcpdf.org/examples.php

+0

如何從單元格中設置保證金或x/y位置?我發現這行:$ pdf-> Cell(0,110,'TEST CELL STRETCH:no stretch',0,1,'',0,'',0); –

+0

檢查此示例:與Multicell()的複雜對齊方式 – Arfeen

9

您可以添加這樣的事情:

$tagvs = array('h1' => array(0 => array('h' => 1, 'n' => 3), 1 => array('h' => 1, 'n' => 2)), 
       'h2' => array(0 => array('h' => 1, 'n' => 2), 1 => array('h' => 1, 'n' => 1))); 
$pdf->setHtmlVSpace($tagvs); 

這裏是從文檔/範例格式描述:

文件:tcppdf.php:

/** 
* Set the vertical spaces for HTML tags. 
* The array must have the following structure (example): 
* $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1))); 
* The first array level contains the tag names, 
* the second level contains 0 for opening tags or 1 for closing tags, 
* the third level contains the vertical space unit (h) and the number spaces to add (n). 
* If the h parameter is not specified, default values are used. 
* @param $tagvs (array) array of tags and relative vertical spaces. 
* @public 
* @since 4.2.001 (2008-10-30) 
*/ 

文件http://www.tcpdf.org/examples/example_061.phps

// REMOVE TAG TOP AND BOTTOM MARGINS 
// 
// $tagvs = array('p' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n' => 0))); 
// $pdf->setHtmlVSpace($tagvs); 
// 
// Since the CSS margin command is not yet implemented on TCPDF, you 
// need to set the spacing of block tags using the above method. 
相關問題