Recent

Author Topic: [SOLVED] Print Long String Memo1.Text  (Read 6389 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: Print Long String Memo1.Text
« Reply #15 on: May 13, 2019, 09:50:47 pm »
Here is SynEdit/Memo1 print project.

Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

andrewc119

  • Newbie
  • Posts: 1
Re: [SOLVED] Print Long String Memo1.Text
« Reply #16 on: February 05, 2024, 08:50:18 pm »
I got this working quite well by tweaking some of the previous.
Andrew

procedure TForm1.FilePrintItemClick(Sender: TObject);
  Var
   i, lineCount, linesPerPage,Pn: integer;
  scaleFactor, lh: single;
  printerRect: TRect;
  textarea: TRect;
  mytextstyle: TTextStyle;
  PageTitle : String;

begin
  If Memo1.lines.count > 0  then
  With PrintDialog1 Do       // pick up the printer name  etc
  begin

  PageTitle := Form1.caption; // for memo1

  Printer.Canvas.Font.Assign(Memo1.Font);
    scaleFactor:=Printer.XDPI / Screen.PixelsPerInch;
    Printer.Canvas.Font.Size:=12;      // was 12    or 10
    Printer.Canvas.Font.Style:=[FSBold]; //bold

      lh:= printer.Canvas.TextHeight(Memo1.text);  //get the height from the memo characters


       lh := Lh * (Printer.Canvas.Font.Size Div 2);   // seems to work


    linesPerPage:=trunc(Size(Printer.PaperSize.PaperRect.WorkRect).cy / lh) - 3;   // was1  allow room for header

   // Form1.caption := Inttostr( linesPerPage);
   // exit;


    printerRect:=Printer.PaperSize.PaperRect.PhysicalRect;
    textarea:=Rect(50,50,Printer.PaperSize.Width - 50,Printer.PaperSize.Height-50);

    mytextstyle := Printer.Canvas.TextStyle;
    mytextstyle.Wordbreak:=True;
    mytextstyle.SingleLine:=False;

     Printer.BeginDoc;
    Pn := 1;
    lineCount:=1;
    try
     Printer.Canvas.TextOut(0,0 , '          Page: '+ IntToStr(Pn)+ '     ' + PageTitle) ;

      for i:=0 to Memo1.Lines.Count-1 do
        begin
           Inc(lineCount);  // leaves a blank line under the title line

           Printer.Canvas.TextOut(200, trunc(lh*lineCount), Memo1.Lines);

            if (lineCount > linesPerPage) then begin
            lineCount:=1;
           Printer.NewPage;
           inc(pn);

             Printer.Canvas.TextOut(0,0 , '          Page: '+ IntToStr(Pn)+ '     ' + PageTitle) ;

          end;
        end;
      Printer.EndDoc;
    except
         //cancelled
    end;
  end;

PascalDragon

  • Hero Member
  • *****
  • Posts: 6381
  • Compiler Developer
Re: [SOLVED] Print Long String Memo1.Text
« Reply #17 on: February 08, 2024, 09:22:52 pm »
I got this working quite well by tweaking some of the previous.

Please use [code=pascal][/code]-tags to avoid the forum software interpreting your code.

 

TinyPortal © 2005-2018