procedure TForm1.Button2Click(Sender: TObject);
var
 F: TextFile;
 TempStr, PageNum: String;
 Ctr, X, PHeight, LineSpace, LinesPerPage, CopyNum, NumCopies: Integer;
begin
 if PrintDialog1.Execute then
 begin
  Ctr := 1;
  AssignFile(F, Fname); { Zwizujemy zmienn z plikiem tekstowym }
  NumCopies := PrintDialog1.Copies;
  for CopyNum := 1 to NumCopies do
  begin
   Reset(F);             { Otwieramy plik }
   Ctr := 1; x := 0;
   Printer.BeginDoc;               { Rozpoczynamy proces drukowania }
   PHeight := Printer.PageHeight;  { Wysoko strony }
   Printer.Canvas.Font.Size := FontDialog1.Font.Size;
   Printer.Canvas.Font.Name := FontDialog1.Font.Name;
   Printer.Canvas.Font.Style := FontDialog1.Font.Style;
   { obliczamy liczb wierszy }
   LinesPerPage := PHeight div (Printer.Canvas.Font.Size * 2);
   { obliczamy odstp midzy wierszami }
   LineSpace := PHeight div LinesPerPage;
   PageNum := IntToStr(Printer.PageNumber);   { Numer strony }
   Label1.Caption :=Now Printing+ PageNum +Page;
   while not Eof(F) do
   begin
    Readln(F, TempStr);      { Pobieramy z pliku kolejny wiersz }
    Printer.Canvas.TextOut(0,x,TempStr);  { Drukujemy go }
    x := x + LineSpace;                   { Zwikszamy wsprzdna pionow }
    Ctr := Ctr + 1;                       { Zwikszamy licznik wierszy }
     if Ctr > LinesPerPage then           { Jeli koniec strony... }
     begin
      Printer.NewPage;     { Nowa strona }
      x := 0;
      Ctr := 0;
      PageNum := IntToStr(Printer.PageNumber);
      Label1.Caption :=Now Printing+ PageNum +Page;
     end;
   end;
   Printer.EndDoc;    { Wysanie danych na drukark }
   CloseFile(F);
   Label1.Caption :=Printing Complete!;
   Label2.Caption :=Number of Copies =+ IntToStr(NumCopies);
  end;
 end;
end;