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.


In reply to Re: Printing various files from Perl and few other things. by Thelonius
in thread Printing various files from Perl and few other things. by techcode

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.