TECH TIP: Send TextFile to Printer
Question: “I designed a application that exports the report to a .txt file using ReportTextFile device. How can I Send the text file to the printer?”
The following procedure will send the .txt file to the printer using Delphi’s TPrinter object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
uses Printers; procedure SendTextFileToPrinter(aFileName: String); var lsLines: TStringList; lOutputFile: TextFile; liIndex: Integer; begin lsLines := TStringList.Create; try lsLines.LoadFromFile(aFileName); AssignPrn(lOutputFile); Rewrite(lOutputFile); for liIndex := 0 to lsLines.Count-1 do Writeln(lOutputFile, lsLines[liIndex]); CloseFile(lOutputFile); finally lsLines.Free; end; end; |