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

In reply to Re: Print to Windows Printer by lamprecht
in thread Print to Windows Printer by keithvb

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.