Commits

Anonymous committed fd7c054

Pierwzsa przymiarka.

Comments (0)

Files changed (1)

print_in_parts.pl

+#!/usr/bin/perl -w
+#
+# Print given file in pieces 20 pages each (workaround
+# for unknown bug in my printer)
+
+package PrintMe;
+use Moose;
+use namespace::autoclean;
+use PDF::API2;
+use List::Util qw(min);
+with 'MooseX::Getopt';
+
+has 'file' => (is => 'ro', isa=>'Str', required => 1,
+               documentation => 'File to print');
+has 'split' => (is => 'ro', isa=>'Int', required => 1,
+                default => sub { 20 },
+                documentation => 'Split every ... pages');
+has 'since' => (is => 'ro', isa=>'Int', required => 1,
+                default => sub { 1 },
+                documentation => 'Start from page ...');
+
+sub run {
+    my $self = shift;
+
+    my $doc = PDF::API2->open($self->file);
+    my $pages_count = $doc->pages;
+    undef $doc;
+    my $start = $self->since;
+    while($start <= $pages_count) {
+        my $end = min($start + $self->split, $pages_count);
+        $self->print_part($self->file, $start, $end);
+        $start = $end + 1;
+    }
+}
+
+sub print_part {
+    my ($self, $filename, $since, $to) = @_;
+
+    my $command = "lp -o media=a4 -o sides=two-sided-long-edge -P '$since-$to' '$filename'";
+    print "Try:\n$command\n";
+}
+
+###########################################################################
+# Main
+###########################################################################
+
+package main;
+
+my $app = PrintMe->new_with_options();
+$app->run();
+
+
+
+