PRINTING DIRECTLY TO USB PORT Back
procedure TPrintfile1.OutputWinPrn(Sender: TObject; FileName: String);
var
FIn,
FOut : File;
Buffer : array [0..1024] of Byte;
RealByte : integer;
ADevice,
ADriver,
APort : string;
PrinterHandle: THandle;
DocInfo1: TDocInfo1;
DS : string;
OutByte: DWORD;
begin
try
AssignFile(FIn,FileName);
Reset(FIn,1);
except
MsgOk('Fout bij openen bronbestand!','Bestand uitvoer');
exit;
end;
setlength(ADevice,80);
setlength(ADriver,80);
SetLength(APort,80);
Printer.GetPrinter(PChar(ADevice),
PChar(ADriver),
PChar(APort),PrinterHandle);
if not OpenPrinter(PChar(ADevice),PrinterHandle, nil) then
begin
StringMsgOk('error ' + IntToStr(GetLastError),caption);
Exit;
end;
with DocInfo1 do
begin
pDocName := PChar(FileName);
pOutputFile := nil;
pDataType := 'RAW';
end;
screen.Cursor:=crHourglass;
StartDocPrinter(PrinterHandle, 1, @DocInfo1);
try
try
if length(InitWin)>0 then
WritePrinter(PrinterHandle,PChar(InitWin),length(InitWin),OutByte);
while not eof(Fin) do
begin
Blockread(Fin,Buffer[0],sizeof(Buffer),RealByte);
setlength(DS,RealByte);
move(buffer[0],DS[1],RealByte);
if not WritePrinter(PrinterHandle,PChar(DS),RealByte,OutByte) then
begin
exit;
end;
end;
if length(ExitWin)>0 then
WritePrinter(PrinterHandle,PChar(ExitWin),length(ExitWin),OutByte);
except
MsgOk('Fout bij verwerken van uitvoer!','Bestand uitvoer');
end;
finally
EndDocPrinter(PrinterHandle);
ClosePrinter(PrinterHandle);
CloseFile(FIn);
screen.Cursor:=crDefault;
end;
end;