Multiple Line output using Win32::Printer

Discussion in 'Perl Misc' started by Jack D, Jun 8, 2006.

  1. Jack D

    Jack D Guest

    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
    Jack D, Jun 8, 2006
    #1
    1. Advertising

  2. Jack D

    Jack D Guest

    "Jack D" <> wrote in message
    news:zmShg.25618$S61.24326@edtnps90...
    > 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.

    > 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
    >
    >
    Jack D, Jun 8, 2006
    #2
    1. Advertising

  3. Jack D

    l v Guest

    Jack D wrote:
    > 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);

    --

    Len
    l v, Jun 8, 2006
    #3
  4. Jack D

    Jack D Guest

    "l v" <> wrote in message
    news:...
    > Jack D wrote:
    > > 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);


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

    Jack
    Jack D, Jun 8, 2006
    #4
  5. Jack D

    l v Guest

    Jack D wrote:
    > "l v" <> wrote in message
    > news:...
    >
    >>Jack D wrote:
    >>
    >>>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);

    >
    >
    > 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".

    --

    Len
    l v, Jun 9, 2006
    #5
  6. Jack D

    Jack D Guest

    Follow Up [was Re: Multiple Line output using Win32::printer]

    "Jack D" <> wrote in message
    news:zmShg.25618$S61.24326@edtnps90...
    > 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;
    }
    }
    Jack D, Jun 10, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Samuel Lee
    Replies:
    0
    Views:
    499
    Samuel Lee
    Nov 11, 2003
  2. Peter A. Schott
    Replies:
    4
    Views:
    584
    Peter A. Schott
    Feb 7, 2006
  3. ruds
    Replies:
    7
    Views:
    502
    John B. Matthews
    Apr 22, 2009
  4. Anders
    Replies:
    3
    Views:
    96
  5. Replies:
    5
    Views:
    131
Loading...

Share This Page