Closed PhilterPaper closed 3 years ago
Reply #1 by Phil
The textlabel()
call does not appear to have been intended for anything more than one-off labels. I will take a look at it to see if I can do anything about its leaving the "next write" position defined (@where = $text->textpos();
). In the meantime, you can either
use the text width returned by textlabel() and add it to your "x" coordinate
use $text->text("Hello World"); instead, which leaves the "next write" position defined
An example of both:
use warnings;
use strict;
use PDF::Builder;
my $pdf = PDF::Builder->new();
my $page = $pdf->page();
my $text = $page->text();
my $font = $pdf->corefont("times-roman");
# output via textlabel()
my $w = $text->textlabel(50,100, $font,10, "Hello World (textlabel)", -hscale=>80);
$text->textlabel(50+$w,100, $font,10, "Next write here", -hscale=>80);
# output via text() or text_left()
$text->font($font, 10);
$text->translate(50,200);
$text->hscale(80);
$text->text("Hello World (text)");
$text->text("Next write here");
$pdf->saveas("where.pdf");
There is also $text->advancewidth("text")
to tell you the width of a slug of text, in the current font and size.
I will move this to the bugs section soon, as either the code or the documentation should be updated.
stueber commented
Dear Phil,
Thanks a lot for your elaborate answer. I tested the program snippet you provided and it works fine for me :)
Greetings Kurt
I don't see a clean way to change the behavior of textlabel() to make it play nicely with other text operations, so I have updated the documentation to clarify that it is a standalone operation.
Closing.
Hello,
sorry for the beginners question:
When I use the textlabel command:
How can I find out where on the paper the right end of this text will be? I would like to know, so that other elements of the page do not overlap or collide with the text.
greetings Kurt