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

I am using the module to enable print functionality on a script I have been working on. As of now I have had to half arse some formatting to get this app to print more than one page with correct text location, etc...

sub print { my $dc = new Win32::Printer( papersize => 1, dialog => 0x000004, description => $filename, unit => 'mm' ); my $font = $dc->Font($font, $size); $dc->Font($font); chomp(my $page = $t->get("1.0", "end")); my @page = split(/\n/, $page); my $lncnt = 0; $lncnt++ for (@page); my $total = (($lncnt/83) + 1); if ($total =~ /\./) { my $trash; ($total, $trash) = split(/\./, $total); } my $y = 15; my @flnm = split(/\//, $filename); my $file = pop(@flnm); my $current = 1; $dc->Write("-- $file --", 20, 5); foreach (@page) { $dc->Write($_, 10, $y); $y+=3; if ($y > 264) { $dc->Write("$current of $total pages", 180, 267); $current++; $dc->Page(); $dc->Write("-- $file --", 10, 5); $y = 15; } if ($current == $total) { $dc->Write("$current of $total pages", 180, 267); } } $dc->Close(); $info = "Print job complete!"; }

This is what I have come up wioth so far and it somewhat works but is too static for my taste. It will only look decent if the user uses portrait and not landscape and the specific style and size font defined. Also as of now text that extends past the edge of the paper is cutoff and does not wrap.

Is there any better built in functionality to this module to allow for easier and more dynamic formatting of the print page layout? I have searched the documentation and have found nothing that will seem to help me with this, although I am sure there is and maybe I am simply overlooking it.


www.perlskripts.com

Replies are listed 'Best First'.
Re: Win32::Printer formatting?
by BrowserUk (Patriarch) on Aug 25, 2004 at 22:45 UTC

    If you want text to be wrapped, then you shouldn't be using the printer in graphics mode. Better to just open the printer and print to it, or even just print to the screen an allow the users to redirect to the printer themselves.

    If you want to continue to have control over the fonts, paper orientation etc., but allow the user to make choices about these, you are into the whole thing of finding out what printers they have installed, querying their capabilities, offering dialogs for font selection etc. That is lots of work.

    It would be much easier to produce your output as html/css (which will take care of wrapping and pagination) to a file and then start the users browser to display it.

    From there, the user can override your choices of fonts and so on using a user defined css file and the browser already has all the required smarts to interface with the printers.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon