Re: How to Access Printer port


Posted by Jean-Claude Servaye on January 30, 2001 at 19:27:39:

In Reply to: How to Access Printer port posted by MOHAMMED WAJEED on January 28, 2001 at 16:38:42:

You can acces the printer with this function
Use a StringList and add all your text in it
then call the function.
So, you don't need to use the port and the printer spool works like for all windows application.

Procedure Form1.PrintRawStr(S : TStringList);
Var
Handle : THandle;
N : DWord;
DocInfo1 : TDocInfo1;
P : Byte;
Printername, A : String;
I : Integer;
Begin
PrinterName := 'Epson'; // type here your reel printer name as installed in windows
If not OpenPrinter(PChar(PrinterName),Handle,nil) then Begin
Case GetLastError of
87 : ShowMessage('Printer name does not exists.');
else
ShowMessage('Error ' + IntToStr(GetLastError));
End;
Exit;
End;

With DocInfo1 do Begin
pDocName := PChar('Test'); // The job name will be shown in
// the printerdialog (double click on the printer icon in the
// system tray when the printer i s printing).
pOutputFile := nil;
pDataType := 'RAW';
end;

StartDocPrinter(Handle,1,@DocInfo1);
StartPagePrinter(Handle);
For I := 0 to S.Count-1 do begin
A := S[I];
N := Length(A);
WritePrinter(Handle,PChar(A),Length(A),N);
end;
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
End;