TextOut to Printer

vegaseat 0 Tallied Votes 244 Views Share

This Delphi procedure sends the text contained in a multiline editbox (memo in Delphi lingo) to a printer. The font and font size can be specified.

// send the lines of a multiline editbox (memo) to the printer
// the form contains at least three components:
// a Button, a MemoBox named TotalCost and a PrintDialog
// note that BLANK is just a space character
// Delphi 3.0
   
procedure TForm1.PrintTotalButtonClick(Sender: TObject);
var
  POutput: TextFile;
  k: Integer;
begin
  if PrintDialog1.Execute then
  begin
    AssignPrn(POutput);
    Rewrite(POutput);
    Printer.Canvas.Font.Name := 'Courier New';
    Printer.Canvas.Font.Size := 8;
    Writeln(POutput,BLANK);
    Writeln(POutput,BLANK);
    Writeln(POutput,BLANK);
    for k := 0 to TotalCost.Lines.Count - 1 do
      Writeln(POutput, '     ' + TotalCost.Lines[k]);
    CloseFile(POutput);
  end;
end;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.