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.
const
TopMargin = 400;
LeftMargin = 500;
BottomMargin = 500;
procedure TfrmPrinterSetUp.PrintOddEven;
var
i, Line, PageCntr, Result : Integer;
begin
Printer.BeginDoc ;
Printer.Canvas.Font.Name := 'MS Sans Serif';
Printer.Canvas.Font.Size := 10;
Printer.Canvas.Font.Color := clBlack;
Line := TopMargin;
PageCntr := 1;
for i := 0 to Memo1.Lines.Count - 1 do
begin
Line := Line + Abs(Printer.Canvas.Font.Height);
if (Line >= Printer.PageHeight - BottomMargin) then
begin
Line := TopMargin;
PageCntr := PageCntr + 1;
if (PageCntr mod 2) = 1 then Printer.NewPage;
end;
if (PageCntr mod 2) = 1 then
Printer.Canvas.TextOut(LeftMargin, Line, Memo1.Lines[i]);
end;
Printer.EndDoc;
lblPageCntr.Caption := IntToStr(PageCntr);
// Prompt user before printing even pages
result := MessageDlg('Even pages will be printed on the back of the paper. Switch paper now?',mtError,mbYesNo,0);
if result = mrYes then
begin
Printer.BeginDoc ;
Printer.Canvas.Font.Name := 'MS Sans Serif';
Printer.Canvas.Font.Size := 10;
Printer.Canvas.Font.Color := clBlack;
Line := TopMargin;
PageCntr := 1;
for i := 0 to Memo1.Lines.Count - 1 do
begin
Line := Line + Abs(Printer.Canvas.Font.Height);
if (Line >= Printer.PageHeight - BottomMargin) then
begin
Line := TopMargin;
PageCntr := PageCntr + 1;
if (PageCntr mod 2) = 0 then Printer.NewPage;
end;
if (PageCntr mod 2) = 0 then
Printer.Canvas.TextOut(LeftMargin, Line, Memo1.Lines[i]);
end;
Printer.EndDoc;
lblPageCntr.Caption := IntToStr(PageCntr);
end;
end;