|
-
April 12th, 2004, 11:21 AM
#1
How to print with printer on linux
I need to print a text (with printer, not to the console) under linux.
The point is that I dont want to print a file(though an example of printing a file would do no harm ), but I want to print some text wich is in varianbles or in xml format...Parsing xml is my problem I just want to know how to print using C++ under linux . Thanks in advance.
-
April 12th, 2004, 11:47 AM
#2
I've never done this before but it used to work in the dos world...
If you create an ofstream to you printer device (prolly dev/lpt0 or something like that) the you can simply stream data to that device as you would the console.
A linux person would have a better answer for you.
-
April 12th, 2004, 03:30 PM
#3
That the point that I dont know how to do it on unix system.... I have plently examples with windows version, but its no use of them...
-
April 12th, 2004, 03:51 PM
#4
I havn't checked it, but you can try using C style,
fprintf(stdprn,"...",...);
**** **** **** **** **/**
-
April 13th, 2004, 10:37 AM
#5
Originally posted by DevLip
I've never done this before but it used to work in the dos world...
If you create an ofstream to you printer device (prolly dev/lpt0 or something like that) the you can simply stream data to that device as you would the console.
OK, let's start with this:
DOS (and with some restrictions everything else from MS) are a single-user OSes, while Linux (and all other UNIXes) are multi-user OSes.
Why am I telling this?
Well on a single-user OS the person running a program must be the same person that owns the printer, thus he can do whatever he likes to the printer and there is no need for things like permissions, queueing, security, etc.
On a multi-user OS, there might be 1000 persons (think of Universitys) logged in to the system and a lot of them want to print something, some might be allowed, some not. This is why printing in multi-user OSes is controlled via a client-server architecture: The server part is the only program in the system allowed to access the actual physical printer. If multiple persons want to print at the same time the server will do the queueing of the jobs. The clients are the programs that print something. They connect only to the server and not to the printer directly.
So to implement printing from your C++ program, you must implement a client:
- Find out which client/server architecture your Linux distribution is actually using (some are cups, lprng, lpr)
- Search the web for a client library to link to your program
- Use system calls from that library to print
If your system uses CUPS, check http://www.cups.org/spm.html for more details.
If you want to print a file, lpr <filename> should do the trick.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|