Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Printer Format Attributes

by UncleSteve (Initiate)
on Dec 18, 2003 at 17:17 UTC ( #315577=perlquestion: print w/replies, xml ) Need Help??

UncleSteve has asked for the wisdom of the Perl Monks concerning the following question:

I've been tasked with writing a PERL script that will run on several different Windows systems - each with their own flavor of printer (Epson, HP, etc.)

There has got to be a way to query the OS for the printer format attributes (bold, underline, font, etc.) for the specific printer attached. I won't know what kinds of printer they have so I can't build the attributes ahead of time.

Can anyone point me in a direction of wisdom?

update (broquaint): added formatting

Replies are listed 'Best First'.
Re: Printer Format Attributes
by davido (Cardinal) on Dec 18, 2003 at 17:59 UTC
    One of the reasons that printer drivers exist is to provide a more generic interface to the specificities of different types of printers. And, like many modern OS's, Win32 manages the printer drivers for you.

    You can poll the Win32 environment to determine what printers are available. For that, use the Win32::Printer::Enum module.

    That module will tell you the driver names and ports on which the printers may be found.

    After figuring out what printer you want to print to, you can use the Win32::Printer module to standardize your printing in a more generic way so that you don't have to deal with the differences between different makes of printers.

    Be sure to read the POD for these modules. Installation appears to be a little tricky.

    Another thought:
    Not worrying about OS-dependant printing issues is one good argument for web-based applications versus workstation based applications. Most web browsers already know how to print. Creating a web-based application (Internet or Intranet) allows you to gloss over details such as "how the hell do I print?" If you're striving for quick development time, it's hard to beat a web-based application when you start needing to do things like printing and screen formatting. If development time isn't an issue, and a polished look is, then I guess it's time to turn to workstation-based applications. Of course one of the reasons people turn to Perl is quick development time. It is in keeping with that philosophy that I mention the web-based approach.


Re: Printer Format Attributes
by chromatic (Archbishop) on Dec 18, 2003 at 17:37 UTC

    Do you mean the attributes of the printer's built-in fonts, if it even has any? I'm not aware of any way to do this. Fortunately (in the sense that it's fortunate that I know it's possible), most printers can print bitmaps, so your task is "simply" to generate something that can be rasterized. If you know your printers all speak PostScript or some variant, you can generate that.

    Again, unfortunately, few consumer-level printers speak PostScript. You could use GhostScript to translate PostScript into the appropriate printer commands, though. It's still a harder problem than you suppose, mostly because I'm not sure there's any one way to get any of the information you want, much less all of it.

    By the way, it's either Perl or perl, but never PERL.

Re: Printer Format Attributes
by eclark (Scribe) on Dec 18, 2003 at 17:52 UTC

    If it is an appropriate way to solve your problem, I would write a PDF and print it. PDF::Template on CPAN looks like it could work for you.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://315577]
Approved by broquaint
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2022-06-26 05:23 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (83 votes). Check out past polls.