in reply to Print a text file to a Windows network printer in a landscape orientation.

It's absolutely a sensible question to ask.

Win32::Printer::Direct is actually a wrapper around functionality provided by Win32::Printer itself. The details of the call it makes don't really appear in the POD nor do they appear in the Perl source of the Win32::Printer module. The call is either, then, in the XS part of the module or a call into the Windows API. I haven't tracked down for you which. The Windows API reference could probably come in handy if you're dealing with this module issue.

There are other ways to handle printing that might be a little more general. If you can expect all of your users to have a PDF reader such as Acrobat Reader or FoxIt, then you could use something based on PDF::API2 and have the PDF reader program handle printing. There's plenty of documentation on that module.

There are also other document formats that might work for you other than PDF that still get you the printing part for free, but that's the one I have recent experience needing to use for printable material from Perl. PostScript comes to mind, as do ODF and .doc files.

  • Comment on Re: Print a text file to a Windows network printer in a landscape orientation.

Replies are listed 'Best First'.
Re^2: Print a text file to a Windows network printer in a landscape orientation.
by iskinner (Novice) on Apr 04, 2008 at 22:17 UTC

    Quote: There are other ways to handle printing that might be a little more general.

    I am most open to any other options to meet this requirement of printing a page to a Windows network printer in landscape orientation. I have tried to explore several options today such is working from the DOS command line. But I have not found anything that quite gets me to the finish line.

    I am not sure your PDF or related suggestions would work, but if I am mistaken please enlighten me. There is no human interaction with the process once it is up and running. The application watches a directory during the quite night time hours. When if finds files are loaded there, it starts extensive processing of them resulting in many many database transactions and several text files.

    One of these text files is sent to a printer where, the following morning, somebody grabs the resulting pages from the output tray, stuffs them into envelopes and mails them all over the State of California.

    If anybody can suggest alternatives to the Win32::Printer{::Direct} option, I am all eyes.

    Thank You
    Ian

      The only other library I know of that lets you print from windows is Wx. There's a nice example in the wdperl_demo.

      You might be able to do something with Word (or perhaps another app) through OLE using Win32::OLE if you know OLE. I don't.


      TGI says moo

      An easy workaround (although not very general) might leverage what type of networked printer you have. A JetDirect print server generally has FTP through which you can transfer any type of file (plain text, PCL, PostScript, raw) the printer attached to it can print. I'm not sure how to specify landscape printing other than at the printer then, though. A PostScript file can specify the orientation of its contents.

      If you're using a networked printer through the UNC path from Windows, you can probably control a PDF or ODF-compatible application on the server via OLE to do the printing. Whether that'd be easier than figuring out the detailed layout methods of Win32::Printer or getting Win32::Printer::Direct to use Win32::Printer's landscape mode I couldn't say.

      In the vein of using the DOS "print" command, that works with your server's print driver IIRC, so you should be able to set all of your printers (if you have more than one) to landscape on the server. Unfortunately, portrait v. landscape settings in the driver never seem to have worked with that command. It lets you specify which printer device to print to, including UNC paths. print /d:\\unc\path filename should work. It's easy enough to share a printer with a name "foo" on the server with a name of "bar", then shell out to print /d:\\bar\foo datafile. If it did landscape, you'd really be in luck.

      If you can get the file to an lpd somewhere from the Windows box, that might be worth investigating as there's an lpr for Windows (probably several). There are also lpd servers that run on Windows, for that matter.

      By using a PostScript-compatible printer, a PostScript document that sets its own orientation, and either the CLI-based print command or an lpr/lpd combo, you might have a solution that way.