Question Locked

how to print in linux with c++ programming?

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

hello
I am new in c++ and I am new in linux.now i want to print with c++ code in linux.please help me.

4 replies

by apotheon

Are you talking about just printing to stdout? If so, the printf function works the same on Linux as on any other OS. If you mean by sending something to a printer, I don't really know, since I've never written software for interacting with printers, and thus never really looked into it.

(edit: If you're looking to send data to a printer, you'll probably want to look into stuff related to lp, cups, and/or postscript, depending on the type of printer you're using and what sort of printer configuration you have on the system. Maybe that'll help you get started searching for relevant information.)

by apotheon

Here's some code that might provide you with an idea of what to do in this [url=http://cboard.cprogramming.com/showthread.php?t=82890][b]Cprogramming.com forum post[/b][/url]. I recommend searching the rest of that forum for more information, and asking further there. The people on that site are the C/C++ experts.

Good luck.

by pointzerotwo1

Good question... I'm looking forward to some answers
from real experts.

I have c++ experience, but not much Linux experience, so
here's what I know and/or assume.

In Linux virtually all i/o (files, network connections, and
devices) are handled as streams. To print, I believe you
would just need to figure out how to open a connection to
the printer and then write to it the same way you would to
a file (printf, iostreams, whatever). Not sure if any extra
steps are required for a network printer (lpr? cups?).

Then you would need to send data to the printer in a
format that the printer understands, which would
probably be PCL or Postscript. I believe libraries are
available that make it possible to generate pcl and
postscript without having to know those languages.

Most laser printers can also print simple text, like the old
dot matrix printers did. If you're printing a simple tabular
report, a text-based format would probably be the easiest
by far.

(Ink jets and cheap laser printers might not support text,
pcl, or postscript, but there may be Linux libraries
available to support the more popular models.)

Sorry I can't provide more details....

This discussion is closed to new replies.