Mega Code Archive

 
Categories / Delphi / Printing
 

How to send a raw string to the printer

Title: How to send a raw string to the printer? Question: How to send a raw string to the printer? On some Laserjets a custom message can be shown on the LCD. You can alter / customize this message by using PrintRawStr. Answer: Procedure PrintRawStr(S : String); //Uses WinSpool; Var Handle : THandle; N : DWord; DocInfo1 : TDocInfo1; P : Byte; Printername : String; Begin Printername := Printer.Printers[0]; //uses printers // Correct Printername for 'on LPT1:' or something like that P := Pos(' on ',PrinterName); If P 0 then PrinterName := Copy(PrinterName,1,P - 1); If not OpenPrinter(PChar(PrinterName),Handle,nil) then Begin Case GetLastError of 87 : ShowMessage('Printer name does not exists.'); else ShowMessage('Error ' + IntToStr(GetLastError)); // Uses Dialogs End; Exit; End; With DocInfo1 do Begin pDocName := PChar('Print job'); // The job name will be shown in // the printerdialog (double click on the printer icon in the // system tray when the printer is printing). pOutputFile := nil; pDataType := 'RAW'; end; StartDocPrinter(Handle,1,@DocInfo1); StartPagePrinter(Handle); WritePrinter(Handle,PChar(S),Length(S),N); EndPagePrinter(Handle); EndDocPrinter(Handle); ClosePrinter(Handle); End;