문제

How to you move text along the y axis using tcpdf? $pdf->Write(150 moves it up and down, I just can't figure out left to right.

http://i.imgur.com/DCBzJNw.png

<?php

// Include the main TCPDF library (search for installation path).
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 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);


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

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

// set JPEG quality
$pdf->setJPEGQuality(75);


// Image example with resizing
$pdf->Image('../../edit1forbrad_program.jpg', 10, 10, 480, 680, 'JPG', 'http://www.tcpdf.org', '', true, 150, '', false, false, 1, false, false, false);

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

if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

$txt = "Some sample text";
$pdf->SetFont('times', '', 16);
$pdf->Write(150, $txt, '', 0, 'L', true, 0, false, false, 0);
//$pdf->Annotation(83, 27, 10, 10, "Text annotation example\naccented letters test: aaeeiioouu", array('Subtype'=>'Text', 'Name' => 'Comment', 'T' => 'title example', 'Subj' => 'example', 'C' => array(255, 255, 0)));



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

//Close and output PDF document
$pdf->Output('example_009.pdf', 'I');
?>
도움이 되었습니까?

해결책

You can manually adjust the Y-axis by calling SetY() before calling Write().

So for example:

$pdf->SetY(30);
$pdf->Write( //Etc. );

But in the case of fitting text into a box like that the best thing, in my opinion, would be to create a MultiCell. You can position a MultiCell by adjusting the X en Y parameters, and a correctly sized MultiCell will make sure no text will go outside of the box, because it will break the line automatically as it reaches the right end of the Cell.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top