Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to print output to printer .

Status
Not open for further replies.

tushar149

Programmer
Oct 22, 2003
26
IN
Hello
I want to know how can we create report in c? Do i have to use others reporting options such as crystal report or any other..if yes, which are they.

And how can we send our output(any output) to printer. In short i want to know which is that c command which sends our output to printer..
Pl help..as i am new to c

Tushar
 
How you send stuff to your printer depends on some of the following.
- your compiler (VC++,gcc)
- your operating system (DOS,Linux,XP)
- your printer (HP,Epson,Laserjet)
- your application type (console,win32-GUI)


--
 
You write your report to a file, and then spool to the printer.

Under DOS (print), unix (lp), windows and visual C++ there is a class to handle print.

You can use the c system function to do this.
 
1)I have BCC(borlands c++ ver 3.0
2) i work both on DOS and windows
3) I have HP printer
4) Console

Actually i am a foxpro programmer. And as i want to shift my platform to c & c++. As you know In foxpro there is option to create report and print it. But in c, i want to know how we can create reports given above details. Please help me & oblige.

I have written many small applications in c which has normal logic like entering Customer data in which you just have to give simle entry screen now suppose if i want to advance further and wanna give Invoice entry screen so how could we build relation between in this two and get output.
 
You might be able to get fairly simple text printing from DOS using something like this

Code:
#include <stdio.h>
int main ( ) {
    fprintf( stdprn, &quot;Hello World\n\f&quot; );
    return 0;
}
Though not too many compilers define stdprn as being the printer.

You could then try
Code:
#include <stdio.h>
int main ( ) {
    FILE *fp = fopen( &quot;LPT:&quot;, &quot;w&quot; );
    if ( fp == NULL ) {
        perror( &quot;Unable to open printer&quot; );
    } else {
        fprintf( fp, &quot;Hello World\n\f&quot; );
        fclose( fp );
    }
    return 0;
}
Various device names exist for the printer, so try some of the following.
[tt]LPT1:
LPT
PRN:
PRN[/tt]
Note, if it doesn't actually write to the printer, you should either get an error message, or a file called say &quot;LPT&quot;.


The &quot;\f&quot; at the end of the text is a &quot;form feed&quot;, which typical laser printers need to force the current page to be actually printed on a sheet of paper.

--
 
Hello

Thanks for information. But suppose i have Network printer then what would be the solution. If it is a network printer then we can't give this device names so what would we do at that time? pl help & oblige.

And also if possible please tell me how can we create report in c i mean how can we send formatted output to printer. Suppose i want to generate INvoice then how can i generate format of invoice and send it to the printer.
Please help.....
 
> But suppose i have Network printer then what would be the solution.
Write it as a windows GUI program of some sort.
This solves things like
- networking issues
- differences between printers

A well-written windows program doesn't care about where a printer is, or what drivers are necessary to interact with the printer.

--
 
Hello

AS i told you i am new to C. But what is the difference between C GUI & normal C application. Can you show me a simple c application which can be written in C. A short one...ofcourse if it solves my printing command problem in C then it is well and good.
 
In a normal C, you would just output the text to a print file. With a gui, all the formating, fonts and stuff would be handled by a Class object.

You would have to embed all the PostScript stuff around your text to generate a regular C output file.

If you invoice is just text, then just write the file out, otherwise it is best to find a class object to do this. I would think there would be one in the gnu or X-windows if you are doing this in UNIX.
 
Hi
Thanks for information. But i have Borland C++ ver 3.0 Complier. Can you give me one or two example of GUI application in borland C++ ver. 3.0.

 
hi

there is only one file in zip file which i had download. I.e extension with .pas. Can you show me on or two examples of how to use this class. And if possible can you also show me how to creat GUI application with examples.
 
Go to and get a trial version of Borland C++ builder.

It is pretty straight forward to build a simple GUI program as you pick and choose the stuff you want, and it generates the proper code.

For instance I think that there is an icon of a printer, and you click and move it down to your app and the Tprinter class is instatiated in your app.

There are other Report types, and many third party plugins which you can use to generate a report.
 
hi

thanks for information again. I will try it. But if possible, can you just give me one example of how to build GUI base application using Tprint class & other stuff.

Thank you.
Tushar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top