[TRUCO DELPHI] Imprimir datos en modo RAW.
delphi
Uses printers, winspool; procedure PrintFile(Const sFileName: String); Const cBUFSIZE = 16384; Type TDoc_Info_1 = record pDocName: pChar; pOutputFile: pChar; pDataType: pChar; end; Var Count : Cardinal; BytesWritten: Cardinal; hPrinter : THandle; hDeviceMode : THandle; Device : Array[0..255] Of Char; Driver : Array[0..255] Of Char; Port : Array[0..255] Of Char; DocInfo : TDoc_Info_1; f : File; Buffer : Pointer; begin Printer.PrinterIndex := -1; Printer.GetPrinter(Device, Driver, Port, hDeviceMode); If Not WinSpool.OpenPrinter(@Device, hPrinter, Nil) Then Exit; DocInfo.pDocName := 'MiDocumento'; DocInfo.pOutputFile := Nil; DocInfo.pDatatype := 'RAW'; If StartDocPrinter(hPrinter, 1, @DocInfo) = 0 Then begin WinSpool.ClosePrinter(hPrinter); Exit; end; If Not StartPagePrinter(hPrinter) Then begin EndDocPrinter(hPrinter); WinSpool.ClosePrinter(hPrinter); Exit; end; System.Assign(f, sFileName); try Reset(f, 1); GetMem(Buffer, cBUFSIZE); While Not Eof(f) Do begin Blockread(f, Buffer^, cBUFSIZE, Count); If Count > 0 Then begin If Not WritePrinter(hPrinter, Buffer, Count, BytesWritten) Then begin EndPagePrinter(hPrinter); EndDocPrinter(hPrinter); WinSpool.ClosePrinter(hPrinter); FreeMem(Buffer, cBUFSIZE); Exit; end; end; end; FreeMem(Buffer, cBUFSIZE); EndDocPrinter(hPrinter); WinSpool.ClosePrinter(hPrinter); finally System.CloseFile(f); end; end;
Saludos!