Re: Printing from an application? Sample code anywhere? If all you want to do is write straight ASCII text to a printer, then
locally defined printers will normally have a device file such as
/dev/lp0 listed on the system.
Remote printers and network printers don't have this ability...you need
to send the data to a remote host so it needs to be able to send
something tangible (such as a text file) and won't allow you to have
direct access to its printer pipes in /dev.
Also, most printers nowadays make use of a printer queue so you can
define the default font, print width, lines per page, etc...this is why
you probably want to have the data you send out go to a printer
back-end such as piobe or rembak and let it do the printing for you.
As MikeK demonstrated, the most efficient way (although not always the
best to hear for a programmer) is to write the report or form you want
to print to a file and then direct that file to the printer using a
system call.
Unless you are willing to write a device driver and include that logic
in your code, you will probably want to send data to printers in that
fashion, so that the software can worry about generating its report and
not concern itself with printing (for example) in Courier 17 because
the 132 column report is actually being printed on an Hp Laserjet that
is only 80 columns wide.
Is there a reason you are dead-set against creating a flat file to
print from? Security issue such as check printing? Special graphics
printing that needs to talk to the device? Don't want to have to build
in the code for creating the file and cleaning it up afterward? |