http://www.perlmonks.org?node_id=235891


in reply to Printing from Perl in Windows

KISS I reckon. If Word can do it then why not save yourself the pain and just script it....

use Win32::OLE; # start Word program die if unable to $word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit; } ) or die 'Cannot start Word'; # let's watch $word->{'Visible'} = 1; # Create new document my $d = $word->Documents->Add; # define selection my $s = $word->Selection; my @lines = ( "This is test line 1", "This is test line 2", "This is test line 3", ); # $c is the color # $start is the start of Range # $end is the end of Range # $r is the Range object my ($c, $start, $end, $r) = (2, 0, 0, ); for my $line (@lines) { $end += length($line) + 1; $s->TypeText($line); # define the Range $r = $d->Range($start, $end); # Set font properties $r->Font->{Size} = 18; $r->Font->{ColorIndex} = $c++; $r->Font->{Name} = 'Courier New'; $s->TypeText("\n"); $start = $end; } # TIMTOWTDI but this will overwrite the above #my $r = $doc->{Content}; #$r->{Text} = 'Hello World!'; #$r->InsertParagraphAfter(); #$r->InsertParagraphAfter(); #$r->InsertAfter('Bye!'); # here is how to print a document $word->ActiveDocument->PrintOut({ Background => 0, Append => 0, Range => wdPrintAllDocument, Item => wdPrintDocumentContent, Copies => 1, PageType => wdPrintAllPages, }); # save the file without a prompt $word->WordBasic->FileSaveAs("c:\\test.doc"); # have a quick look at the objects and properties # don't try to Dumper the whole thing unless you have time and memory+ ++ print "Range: $_ => $r->{$_}\n" for sort keys %$r; print "Doc: $_ => $d->{$_}\n" for sort keys %$d; # house keeping, clean up our instances $d->Close(); $word->Quit(); undef $word;

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print