Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-28-2001, 06:26 AM
mdwajeed mdwajeed is offline
Junior Member
 
Join Date: Jan 2001
Posts: 2
Default HOW TO SEND OUTPUT TO PRINTER DIRECTLY

Will you please tell me how to access Printer port directly and send output to printer. I require this for printing the output in dot matrix mode.

Any tips will be great deal of help for me.

Thanks in advance
Reply With Quote
  #2  
Old 01-28-2001, 08:35 AM
Claude Claude is offline
Senior Member
 
Join Date: Jan 2001
Posts: 178
Default RE: HOW TO SEND OUTPUT TO PRINTER DIRECTLY

You do not (and should not) have to send data directly to the printer port. This way, you will be able to print on any network printer. The trick is to open the printer by its name and send raw data to it. You therefore can send text as well as escape sequences. Every byte will be directly sent to the selected printer.

uses WinSpool;

procedure PrintOnDotMatrix;
var
Handle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
s : string;
begin
if not OpenPrinter(PChar('DotMatrix'), Handle, nil) then begin
ShowMessage('Printer «DotMatrix» not found.');
Exit;
end;

with DocInfo1 do begin
pDocName := PChar('Document Name');
pOutputFile := nil;
pDataType := 'RAW';
end;

StartDocPrinter(Handle, 1, @DocInfo1);

s := 'First line of first page' + #13 + #10;
WritePrinter(Handle, PChar(s), Length(s), N);
s := 'Second line of first page' + #13 + #10;
WritePrinter(Handle, PChar(s), Length(s), N);

EndPagePrinter(Handle);

s := 'First line of second page' + #13 + #10;
WritePrinter(Handle, PChar(s), Length(s), N);
s := 'Second line of second page' + #13 + #10;
WritePrinter(Handle, PChar(s), Length(s), N);

EndPagePrinter(Handle);

EndDocPrinter(Handle);

ClosePrinter(Handle);
end;
Reply With Quote
  #3  
Old 01-29-2001, 02:08 AM
VVM VVM is offline
Junior Member
 
Join Date: Jan 2001
Posts: 17
Default RE: HOW TO SEND OUTPUT TO PRINTER DIRECTLY

Some monthes ago I met this problem and I have written
a small unit to direct printing the file or text to printer.
If you want to receive this unit I can send it to you.
My e-mail:
v_matroskin@aport2000.ru
Reply With Quote
  #4  
Old 01-29-2001, 03:29 PM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: HOW TO SEND OUTPUT TO PRINTER DIRECTLY

Hi Use this code to send Escape code to my POS printer but you can modify the code alittle to fit youre need.

type
TPassThroughData = record
nLen: Integer;
Data: array[0..255] of Byte;


end;

var
PTBlock: TPassThroughData;
s: string;
begin


s:=#27+#112+#0+#25+#250; // <- just type what you
//want to print

Printer.BeginDoc;

PTBlock.nLen := Length(s);
StrPCopy(@PTBlock.Data, s);
Escape(Printer.Handle, PASSTHROUGH, 0, @PTBlock, nil);

Printer.EndDoc;

end;


Thats it.This code will surely work for you.

Bye
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:30 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.