I am trying to incorporate print capabilities to an app I have written and have trie Net::Printer, Win32::Printer::Enum and one other and none seem to work. I am not sure if I am using the syntax right or am using the wrong module all together.

I am writing this as for the Win32 OS platform and was under the impression that Win32::Printer::Enum was the correct one. Also Printer is non-platform specific so I tried that also. But as I said neither have worked.

Has anyone had any success using either of these or have any others they have successfully printed a file with? If anyone has I could really use a snippet to show me the correct syntax.

Here was my last attempt at using the Print module.

my $printer = new Printer('linux' => 'lp', 'MSWin32' => 'LPT1'); $printer->print_command('linux' => {'type' => 'pipe', 'command' => 'lpr -P lp'}, 'MSWin32' => {'type' => 'command', 'command' => 'gswin32c -sDEVICE=m +swinpr2 -dNOPAUSE -dBATCH $spoolfile'} ); sub print { my $pw = MainWindow->new(-title=>"Printer Options"); my $frame = $pw->Frame->pack(-side => 'top', -fill => 'x'); $frame->Button(-text => "Show Printers", -background => 'navy blue' +, -foreground => 'white', -command => \&show_printers)-> pack(-side => 'right'); $frame->Button(-text => "Print File", -background => 'navy blue', - +foreground => 'white', -command => \&print_file)-> pack(-side => 'left'); sub print_file { $status->delete("1.0", "end"); $status->insert("end", "Printing Document...."); my $target = $t->get("1.0", "end"); $printer->use_default; $printer->print($target); $status->insert("end", "done\n"); } sub show_printers { my %available_printers = $printer->list_printers(); foreach my $key (%available_printers) { foreach my $field (qw/name port/) { print $field, "=", $$key{$field}, " "; } } } sub list_jobs { my @queue = list_jobs(); foreach my $ref (@queue) { foreach my $field (qw/Rank Owner Job Files Size/) { print $field, " = ", $$ref{$field}, " "; } print "\n"; } } }
I have not addes a third button for the ques jobs yet but was trying to work on the backend first. I of course get an error here saying the barewaord names I have for hash fields cannot be used while strict subs is in use. However I still do not like the way this is laid out and think there has got to be a better way to simply print a file to a printer.

In reply to Need printer help. by Elijah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.