Trying to use c++ to print to a usb printer

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2006
Posts: 32
Reputation: muthuivs is an unknown quantity at this point 
Solved Threads: 0
muthuivs muthuivs is offline Offline
Light Poster

Trying to use c++ to print to a usb printer

 
0
  #1
Feb 9th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,331
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1453
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Trying to use c++ to print to a usb printer

 
0
  #2
Feb 9th, 2006
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).
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 32
Reputation: muthuivs is an unknown quantity at this point 
Solved Threads: 0
muthuivs muthuivs is offline Offline
Light Poster

Re: Trying to use c++ to print to a usb printer

 
0
  #3
Feb 9th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: Trying to use c++ to print to a usb printer

 
0
  #4
Feb 9th, 2006
Do you have to print to the printer directly? And is this related to your other thread?
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 32
Reputation: muthuivs is an unknown quantity at this point 
Solved Threads: 0
muthuivs muthuivs is offline Offline
Light Poster

Re: Trying to use c++ to print to a usb printer

 
0
  #5
Feb 9th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 219
Reputation: BountyX is an unknown quantity at this point 
Solved Threads: 8
BountyX's Avatar
BountyX BountyX is offline Offline
Code Guru

Re: Trying to use c++ to print to a usb printer

 
0
  #6
Feb 9th, 2006
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.
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,331
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1453
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Trying to use c++ to print to a usb printer

 
0
  #7
Feb 9th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: Trying to use c++ to print to a usb printer

 
0
  #8
Feb 10th, 2006
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?
  1. foo bar foo bar foo bar foo bar foo bar
  2. foo bar foo bar foo bar foo bar foo ba
  3. r foo bar foo bar foo bar foo bar foo b
  4. ar foo bar foo bar foo bar foo bar foo
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 32
Reputation: muthuivs is an unknown quantity at this point 
Solved Threads: 0
muthuivs muthuivs is offline Offline
Light Poster

Re: Trying to use c++ to print to a usb printer

 
0
  #9
Feb 10th, 2006
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


Originally Posted by dwks
Like this?
  1. foo bar foo bar foo bar foo bar foo bar
  2. foo bar foo bar foo bar foo bar foo ba
  3. r foo bar foo bar foo bar foo bar foo b
  4. ar foo bar foo bar foo bar foo bar foo
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC