Skip to content

Commit

Permalink
added automatic cropping to content's height
Browse files Browse the repository at this point in the history
  • Loading branch information
sonntagd committed Jul 8, 2017
1 parent bbd382d commit 9392d9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ license = Perl_5
copyright_holder = Dominic Sonntag
copyright_year = 2017

version = 0.002
version = 0.003

[@Basic]

Expand Down
8 changes: 6 additions & 2 deletions lib/Printer/ESCPOS/PDF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ sub new {
my $class = shift;
my $options = \%{ shift() || {} };

$options->{width} ||= 512;
$options->{margin} ||= 10;
$options->{width} += $options->{margin} * 2;

$options->{pdf} = PDF::API2->new();
$options->{page} = $options->{pdf}->page();
$options->{page}->mediabox($options->{width} ||= 512, $options->{height} ||= 1200);
$options->{page}->mediabox($options->{width}, $options->{height} ||= 1200000);
$options->{font} = $options->{pdf}->corefont('Courier');
$options->{font_bold} = $options->{pdf}->corefont('Courier-Bold');
$options->{font_italic} = $options->{pdf}->corefont('Courier-Oblique');
$options->{font_bold_italic} = $options->{pdf}->corefont('Courier-BoldOblique');
$options->{fontsize} ||= 14;
$options->{margin} ||= 10;
$options->{x} = $options->{margin};
$options->{y} = $options->{height} - $options->{fontsize} - $options->{margin};

Expand All @@ -77,6 +80,7 @@ Outputs the generated PDF file to the given file.

sub save_pdf {
my ($self, $filename) = @_;
$self->{page}->mediabox(0, $self->{y} - $self->{margin}, $self->{width}, $self->{height});
$self->{pdf}->saveas($filename);
}

Expand Down

0 comments on commit 9392d9a

Please sign in to comment.