keithvb has asked for the wisdom of the Perl Monks concerning the following question:

Trying to print from Perl to my local printer. Using Active Perl v5.10.1, Win32::Printer. I'm able to print stuff on a page but what I need to do is print the text generated by my script to a printer. Actually the text is in a frame. thanks, Keith

Replies are listed 'Best First'.
Re: Print to Windows Printer
by ww (Archbishop) on May 09, 2010 at 21:44 UTC

    quoth CPAN re Win32::Printer:

    ABSTRACT ^
    DISCONTINUED!!! Win32 GDI graphical printing ...
    (and at 0.9.1, which reminds me of the old advice that one should never buy or use version 1.0 of anything)

    OTOH, PM offers alternatives:

    1. TGI's reply to node 678462 suggests using wx.
    2. Q&A has How do I send a file to the printer on Win32?
    3. and if you really want to get down to somewhat closer to where the metal meets the road, Win32::API

    Hint: Super Search or Google could have helped here.

    Update: In light of BrowserUk's well-made point (below), it seems to me that unless keithvb has some really good reason to output to html, he might also want to consider sending the data direct to a printer; to a text, .pdf or .rtf file; or skipping the html/browser phase (or tee'ing the data to it).

Re: Print to Windows Printer
by BrowserUk (Patriarch) on May 09, 2010 at 22:38 UTC

    Essentially, what you are asking ,is to print the results of rendering html in a browser. And the only way you'll do that with any degree of success is to use a browser.

    You might look into driving your favorite browser using Win32::OLE. Assuming it is OLE compatible--which probably limits it to IE.

    Or you could try controlling the browser by simulated keystrokes via Win32::GUITest.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Print to Windows Printer
by lamprecht (Friar) on May 10, 2010 at 19:15 UTC
    Hi,

    you asked the same question on the perl/Tk mailing list.
    If you are asking about printing from a Tk app, here is a very simple way to do that in wysiwyg quality:

    use warnings; use strict; use Tk; my $mw = tkinit; my $c = $mw->Canvas()->pack; $c->createText(20,20, -text => "some text to test\nand one more line", -font => ['Helvetica'], -anchor => 'w', ); $mw->Button(-text => 'print', -command => sub{print_canvas( $c )}, )->pack; MainLoop; sub print_canvas{ my $c = shift; # draw a mark to enforce a minimum printing area $c->createLine qw/15c 20c 15.1c 20c -fill white/; #calculate printing area, add margin to width and height my @bbox = $c->bbox('all'); my $width = $bbox[2] - $bbox[0] + 50; my $height = $bbox[3] - $bbox[1] + 90; my $ps = $c->postscript( -height => $height, -width => $width, -x => '-1c', -y => '-1c', ); my $gs_cmd = 'gswin32c.exe'; my $gs_options = '-sDEVICE=mswinpr2 -dEPSFitPage'; open my $writeme, "|-","$gs_cmd $gs_options -" or die "Can't open pipe to gs: $!"; print $writeme $ps or die " Error in printing to pipe: $!"; close $writeme or die " Error in closing pipe: $!";; }

    This requires Ghostscript to be installed on your system and the gswin32c.exe to be in your path.

    Other useful options are  '-sDEVICE=pdfwrite' '-sOutputFile="file"' '-sPAPERSIZE=aPapersize'

    Cheers, Chris
      Thanks, Chris. Works perfectly. Now I need to get it to print the contents of my frame. Keith