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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi I need to print barcode to t 1

Status
Not open for further replies.

Bijesz

Programmer
Apr 10, 2003
2
0
0
HU
Hi

I need to print barcode to to a thermal transfer printer which is using special programming language.
So I need to send plain text to the printer port.

Normally from command prompt i can use this command to print it : "type print.txt >lpt1".
From delphi I can run it with winexec, before it creating the text file, but there must be a more elegant way than executing a shell command.

Do anyone know a better solution?

Thanx
Bijesz
 
Maybe there is a more elgant way, but I develop applictions where labels are being printed out 30-40 times per minute and using the shell command works fine for me...

Andrew
 
Well yes there is. You have to use the TPrinter object in Delphi. Look at the following example:

procedure PrintLabel;
begin
try
Printer.BeginDoc; // Printer is a global variable in
// Delphi which you can use.
// BeginDoc places a print job
// in the printer queue of the
// windows default printer so make
// sure your labelprinter is
// installed with its windows drivers
// and selected as the default
// windows printer.

// Place all your printer commandos here
Printer.Canvas.TextOut(0,0, 'Test string');

// EndDoc is the procedure that starts the printing.
Printer.EndDoc;
except
// If anything goed wrong than the print job is deleted
// from the printer queue
Printer.Abort;
end;
end;

You have to place "printers" in your uses list.

Good luck.
 
I have had the same problem converting from a DOS based label printing program to a delphi program and tackled it this way

procedure PrintLabel;
var
sOutPutTo : TextFile;
sLabelData : String;
begin

AssignFile(sOutPutTo, 'LPT1');

ReWrite(sOutPutTo);

WriteLn(sOutPutTo, sLabelData);

System.CloseFile(sOutPutTo);

end;

Nice and easy
 
Yeah, but then the printer & port is hardcoded in your source. What-if the next printer is connected through USB or network?
The Printer.Document model is a much better solution IMHO, as it can reach any printer known to your local windows configuration.

HTH
TonHu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top