Позиция h1, h2, h3 и другие теги с TCPDF - PullRequest
3 голосов
/ 24 ноября 2011

Я пытаюсь создать документ PDF с TCPDF с использованием кода HTML.

На данный момент я использую этот код:

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

Как мне разместить этот текст? Я не могу использовать между тегами margin-top и т. Д.

Может кто-нибудь помочь мне с этой проблемой?

Ответы [ 2 ]

9 голосов
/ 30 октября 2012

Вы можете добавить что-то вроде этого:

$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.
0 голосов
/ 24 ноября 2011

Вы используете writeHTML, который точно превосходит HTML, вам нужно использовать функцию "$pdf->Cell".Здесь есть много примеров http://www.tcpdf.org/examples.php

...