Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/Printer/ESCPOS/PDF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,22 @@ sub text {
my ($self, $string) = @_;
my $text = $self->{page}->text();
$text->font($self->{bold} ? $self->{font_bold} : $self->{font}, $self->{fontsize});
$text->translate($self->{x}, $self->{y});
my $text_width = length($string) * 9; # guessing the Text length

my $x = $self->{x};

if (defined $self->{justify}) {
if ($self->{justify} eq 'center') { # Centered
$x = ($self->{width} - $text_width) / 2;
} elsif ($self->{justify} eq 'right') { # right-aligned
$x = $self->{width} - $self->{margin} - $text_width;
} elsif ($self->{justify} eq 'left') { # left-aligned
$x = $self->{margin};
}
}

$text->translate($x, $self->{y});
$text->text($string);
$self->{x} += int(length($string) * 10);
}

sub lf {
Expand Down Expand Up @@ -233,4 +246,4 @@ same terms as the Perl 5 programming language system itself.

=cut

1;
1;