temuri
temuri

Reputation: 2807

PDFlib - change origin of text to top-left from default of bottom-left

In pdflib:

$font = $p->load_font("Helvetica", "unicode", "");
$p->setfont($font, 12);
$p->set_text_pos(100, 100);
$p->show('My text');

First arguments of set_text_pos($x, $y) tells library where to position bottom-left corner of text element.

Question. How can I change the origin of text to be top-left corner, so that "My text" string appears below 100x100 coordinate?

Upvotes: 2

Views: 880

Answers (1)

Rainer
Rainer

Reputation: 2185

I would recommend to use the more comfortable fit_textline() call. In this case, you can replace your four lines with a single line:

$p->fit_textline('My text', 100, 100, 'fontname=Helvetica encoding=unicode fontsize=12 position {top left} ');

Upvotes: 1

Related Questions