DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Trying to use c++ to print to a usb printer (http://www.daniweb.com/forums/thread39367.html)

muthuivs Feb 9th, 2006 4:06 am
Trying to use c++ to print to a usb printer
 
Does anyone know how to get a c++ program to output to a usb printer or at the very least an acrobat distiller? I am trying to use the following:

ofstream print;
print.open("lpt1:", ios::out);

print<<"blah blah blah";


but I guess I have a usb printer and not a lpt1 printer. PLease help...I am going crazy here!!! :-)

MuthuIVS

Ancient Dragon Feb 9th, 2006 9:12 am
Re: Trying to use c++ to print to a usb printer
 
You can use the printer's device driver and win32 API OpenPrinter and associated functions. (Scroll down to the bottom of the page and you will find other links).

muthuivs Feb 9th, 2006 11:39 am
Re: Trying to use c++ to print to a usb printer
 
Where is the printer name, What is a printer hadle and printer defaults. I am not sure what to pass into these parameter : OpenPrinter(PrinterName ,PrintHandle,&PrinterDefault)

Sorry, just have never had to print directly to a printer other than in COBOL.

MuthuIVS

dwks Feb 9th, 2006 6:01 pm
Re: Trying to use c++ to print to a usb printer
 
Do you have to print to the printer directly? And is this related to your other thread?

muthuivs Feb 9th, 2006 7:10 pm
Re: Trying to use c++ to print to a usb printer
 
Actually it is related to my other thread about making labels. I have tried outputting to a text file with 4 labels across and 20 vertically. The problem I am running into is that once it starts printing the next line it works ok but it starts shifting up a little so by the time the program prints anywhere between the middle and last rows are all shifted and the text isnt aligning with labels.

Is there a way to at least reduce my endl character to 0.5 points or something?

BountyX Feb 9th, 2006 8:01 pm
Re: Trying to use c++ to print to a usb printer
 
Instead of using a text file, use another format that lets you adjust the hieght between lines of the character and the page width. Check out RTF format.

Ancient Dragon Feb 9th, 2006 11:57 pm
Re: Trying to use c++ to print to a usb printer
 
Quote:

Originally Posted by muthuivs
Where is the printer name, What is a printer hadle and printer defaults. I am not sure what to pass into these parameter : OpenPrinter(PrinterName ,PrintHandle,&PrinterDefault)

Sorry, just have never had to print directly to a printer other than in COBOL.

MuthuIVS

You have to name the printer when you installed it. Start --> Printers & Faxes dialog will show all the printers that are installed on your computer.

There are some printer MFC and non-MFC c++ classes at www.codeproject.com that you can use as examples. Printing can become pretty complex, especially if you want lines such as on a form.

dwks Feb 10th, 2006 9:45 pm
Re: Trying to use c++ to print to a usb printer
 
Quote:

The problem I am running into is that once it starts printing the next line it works ok but it starts shifting up a little so by the time the program prints anywhere between the middle and last rows are all shifted and the text isnt aligning with labels.
Like this?
foo bar foo bar foo bar foo bar foo bar
 foo bar foo bar foo bar foo bar foo ba
r foo bar foo bar foo bar foo bar foo b
ar foo bar foo bar foo bar foo bar foo

muthuivs Feb 10th, 2006 10:32 pm
Re: Trying to use c++ to print to a usb printer
 
No, the verticle distance of the printed charachters start to get smaller. but I have decided to get the program to write to a rtf file and use a rtf label template. It seem to work better than text files and simpler than a USB printer headache.

MuthuIVS


Quote:

Originally Posted by dwks
Like this?
foo bar foo bar foo bar foo bar foo bar
 foo bar foo bar foo bar foo bar foo ba
r foo bar foo bar foo bar foo bar foo b
ar foo bar foo bar foo bar foo bar foo



All times are GMT -4. The time now is 8:41 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC