in reply to Printing various files from Perl and few other things.

For many file types, there is a shell extension installed so that you can print using the (right-click) context menu from Windows Explorer. You can use these shell extensensions from Perl. (This uses Win32::API, which I think comes with Active Perl 5.8 and above.)
#!perl -w use Win32 qw(SW_SHOWNORMAL); use Win32::API; use strict; my $shellexec = Win32::API->new('shell32', 'ShellExecute', 'NPPPPI', ' +N') or die "cannot import ShellExecute: $!\n"; for my $filename ( "small.pdf", "realfilebutunknownextension.qqt", "notanexistingfile.doc", "knownextbutnoprint.wpl") { my $result = $shellexec->Call(0, "print", $filename, "", ".", SW_SHOWNORMAL); my $msg = ($result>32)?"Success": Win32::FormatMessage($result); printf "ShellExecute(, \"print\", \"%s\", ...) => %s\n", $filename, +$msg; }
This code checks to see whether the "print" action was started, but there's no way to tell whether it successfully finished.

You can see whether a file has an associated "print" action in Windows Explorer. Click on "Tools|Folder Options", then the "File Types" tab, and, for any extension, click "Advanced." Note that these usually just use command-line options to the associated windows application. For example, my PDF print command is:

"C:\Program Files\Adobe\Acrobat 4.0\Acrobat\Acrobat.exe" /p /h "%1"

There are also inexpensive file viewers that you can get download, either as standalone applications or as ActiveX controls that you can control using Win32::OLE.

See this Google search, e.g.

Replies are listed 'Best First'.
Re^2: Printing various files from Perl and few other things.
by techcode (Hermit) on Jul 11, 2005 at 10:06 UTC
    OK I now have several ways to try - I should be able to make at least one of them work.

    But what's bugging me now. Is there any way to control which printer should do the job? This guy has several (network) printers and while they will (probably) all be the same type. They are in different places.

    I believe that ways that you folks suggested would print by using default printer and it's default settings.

    Anyway, the command prompt way seems easiest :)