i write code for something , now i want to have a printed copy of the softcopy output.How can i get hardcopy output using c++. i think i have to use to include some libraries to the program but i don't know where to get these library or if there exist any other method which don't require additional libraries.

i don't have any idea about it .?

Recommended Answers

All 7 Replies

how to send text/graphics to a printer depends on the operating system. If the printer is attached to LPT1 port (most are USB or wifi nowdays) then just open LPT1 as if it were a text file. Otherwise it's pretty complicated, as shown in this Microsoft article

I don't know how to do it with Linux computers, something to do with postscript.

printer is a very low-level stuff. there are hundreds of libs out there but you must consider a GUI like QT thats a multi platform. The best GUI in town.

Printing in Unix/Linux would usually go through low-level utilities such as lpr and lpq. You don't have to make a postscript file if you just want to print a simple text file (postscript files is what you need for general fancy graphics, e.g., formatted text and images, and that is true for both Windows and Linux, as postscript files are the file format that printers "understand").

From a C++ program, what you would normally do is create a text file with whatever you want, and then issue a system command to send that file to the printer:

std::system("lpr my_file.txt");

which uses the lpr tool.

BTW, Windows uses the same utility (lpr) for simple printing tasks. (which is not suprising since this stuff pre-dates even the existence of Microsoft and DOS)

If you want to have fancier printing outputs, I suggest you look into using another toolset to prepare the document. For example, you could generate a tex file out of a basic template into which you insert to text, and then, generate a postscript / pdf file from that (using the tex / latex / pdftex programs). This is pretty standard because building all the formatting and alignment and stuff like that, and creating files like postscripts / pdfs, is not a simple task, but creating a tex file from a template is trivial, and let the tex toolset deal with the "rendering" of it.

thanks for your replies

std::system("lpr my_file.txt");

gives error in Window OS saying Illegal Command :lpr.

There is no such command in MS-Windows -- lpr is a linux program.

so , whats lpr equivalent in Window ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.