Recent

Author Topic: Printing on both sides with normal printer  (Read 1437 times)

Sprek Skik

  • New Member
  • *
  • Posts: 21
  • Beginner Lazarus & Free Pascal
Printing on both sides with normal printer
« on: May 22, 2024, 09:47:27 pm »
I came into contact with the Lazarus program at the end of last year.
Through trial and error, I have been able to create my own applications.
It is a fun challenge and if I see a problem there are my old Pascal books,
the internet and now also this forum. I am still a real beginner and have very little experience
with everything. Every now and then I have a little success.
So also with the problem of printing on both sides of an A4 sheet.
For me it was a challenge to make this a success with little information.
I hope that I especially do the beginners a favor with this.


Code: Pascal  [Select][+][-]
  1. const
  2.   TopMargin = 400;
  3.   LeftMargin = 500;
  4.   BottomMargin = 500;
  5.  
  6. procedure TfrmPrinterSetUp.PrintOddEven;
  7. var
  8.   i, Line, PageCntr, Result : Integer;
  9. begin
  10. Printer.BeginDoc ;
  11. Printer.Canvas.Font.Name := 'MS Sans Serif';
  12. Printer.Canvas.Font.Size := 10;
  13. Printer.Canvas.Font.Color := clBlack;
  14. Line := TopMargin;
  15. PageCntr := 1;
  16. for i := 0 to Memo1.Lines.Count - 1 do
  17. begin
  18.   Line := Line + Abs(Printer.Canvas.Font.Height);
  19.   if (Line >= Printer.PageHeight - BottomMargin) then
  20.     begin
  21.       Line := TopMargin;
  22.       PageCntr := PageCntr + 1;
  23.       if (PageCntr mod 2) = 1 then Printer.NewPage;
  24.     end;
  25.     if (PageCntr mod 2) = 1 then
  26.       Printer.Canvas.TextOut(LeftMargin, Line, Memo1.Lines[i]);
  27. end;
  28. Printer.EndDoc;
  29. lblPageCntr.Caption := IntToStr(PageCntr);
  30. // Prompt user before printing even pages
  31. result := MessageDlg('Even pages will be printed on the back of the paper. Switch paper now?',mtError,mbYesNo,0);
  32. if result = mrYes then
  33.   begin
  34.     Printer.BeginDoc ;
  35.     Printer.Canvas.Font.Name := 'MS Sans Serif';
  36.     Printer.Canvas.Font.Size := 10;
  37.     Printer.Canvas.Font.Color := clBlack;
  38.     Line := TopMargin;
  39.     PageCntr := 1;
  40.     for i := 0 to Memo1.Lines.Count - 1 do
  41.       begin
  42.         Line := Line + Abs(Printer.Canvas.Font.Height);
  43.         if (Line >= Printer.PageHeight - BottomMargin) then
  44.           begin
  45.             Line := TopMargin;
  46.             PageCntr := PageCntr + 1;
  47.             if (PageCntr mod 2) = 0 then Printer.NewPage;
  48.           end;
  49.      if (PageCntr mod 2) = 0 then
  50.        Printer.Canvas.TextOut(LeftMargin, Line, Memo1.Lines[i]);
  51.    end;
  52.    Printer.EndDoc;
  53.    lblPageCntr.Caption := IntToStr(PageCntr);
  54.  end;
  55. end;
  56.  
  57.  

jamie

  • Hero Member
  • *****
  • Posts: 6734
Re: Printing on both sides with normal printer
« Reply #1 on: May 22, 2024, 11:40:17 pm »
Beware that some printers can print double sided.  If you set that up, you don't have to worry about simulating it.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018