Multiple Line output using Win32::Printer

J

Jack D

I'm trying to output mutilple lines to a printer using Win32::printer. I
have only suceeded in printing one line so far. Does anyone know how force
it to print multiple lines? The output is shows rectangles in between each
word.

Sample code below

use strict;
use Win32::printer;
my @array = keys %ENV;

printMultiple();

sub printMultiple {
my $dc = new Win32::printer( papersize => A4,
description => 'Test,
unit => 'mm') or die "Failed to
create printer object";
if ($dc) {
my $textToPrint = join("\r\n",@oldarray);
my $font = $dc->Font('Times New Roman', 12);
$dc->Font($font);
$dc->Color(0, 0, 0);
$dc->Write($textToPrint, 10, 10);
$dc->Close;
}
}
__END__

Jack
 
J

Jack D

Jack D said:
I'm trying to output mutilple lines to a printer using Win32::printer. I
have only suceeded in printing one line so far. Does anyone know how force
it to print multiple lines? The output is shows rectangles in between each
word.

Sample code below

use strict;
use Win32::printer;
my @array = keys %ENV;

printMultiple();

sub printMultiple {
my $dc = new Win32::printer( papersize => A4,
description => 'Test,
unit => 'mm') or die "Failed to
create printer object";
if ($dc) {
my $textToPrint = join("\r\n",@oldarray);

Oops - this should be
my $textToPrint = join("\r\n",@array);
but it still doesn't work.
 
L

l v

Jack said:
I'm trying to output mutilple lines to a printer using Win32::printer. I
have only suceeded in printing one line so far. Does anyone know how force
it to print multiple lines? The output is shows rectangles in between each
word.

Sample code below

use strict;
use Win32::printer;
my @array = keys %ENV;

printMultiple();

sub printMultiple {
my $dc = new Win32::printer( papersize => A4,
description => 'Test,
unit => 'mm') or die "Failed to
create printer object";
if ($dc) {
my $textToPrint = join("\r\n",@oldarray);
my $font = $dc->Font('Times New Roman', 12);
$dc->Font($font);
$dc->Color(0, 0, 0);
$dc->Write($textToPrint, 10, 10);
$dc->Close;
}
}
__END__

Jack

What does you print show when you change the "\r\n" in the join to ':'?
my $textToPrint = join(':',@oldarray);
 
J

Jack D

l v said:
What does you print show when you change the "\r\n" in the join to ':'?
my $textToPrint = join(':',@oldarray);

Is this a trick question? It prints the colon of course.

Jack
 
L

l v

Jack said:
Is this a trick question? It prints the colon of course.

Jack

No trick, a diagnostic question since you did not include an example of
the output. Then the rectangles that are printed are either from the
\r or the \n. Try with just the \n and see what happens. Did you get
the rectangles? Did you get the print you wanted? Try with the \r and
do the same test. Try with "\n\n".
 
J

Jack D

Jack D said:
I'm trying to output mutilple lines to a printer using Win32::printer. I
have only suceeded in printing one line so far. Does anyone know how force
it to print multiple lines? The output is shows rectangles in between each
word.

Sample code below

use strict;
use Win32::printer;
my @array = keys %ENV;

printMultiple();

sub printMultiple {
my $dc = new Win32::printer( papersize => A4,
description => 'Test,
unit => 'mm') or die "Failed to
create printer object";
if ($dc) {
my $textToPrint = join("\r\n",@oldarray);
my $font = $dc->Font('Times New Roman', 12);
$dc->Font($font);
$dc->Color(0, 0, 0);
$dc->Write($textToPrint, 10, 10);
$dc->Close;
}
}
__END__
Just a follow up for any future Googlers.

After a direct e-mail to the Edgars Binans, the solution is to either write
in "draw mode", use Write2 or print the array element by element
incrementing the y value as you go. Working code below:

use Win32::printer;

my @array = keys %ENV;

printAlpha();

sub printAlpha {
my $dc = new Win32::printer(
papersize => A4,
description => 'Test Print',
unit => 'pt')
or die "Failed to create object";

if ($dc) {

my $font = $dc->Font('Times New Roman', 10);
$dc->Font($font);
$dc->Color(0, 0, 0);
my $v = 10;
foreach my $line (@array) {
$dc->Write($line, 10, $v);
$v+=10;
}
$dc->Close;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top