Lazarus

Programming => LCL => Topic started by: Pe3s on August 15, 2022, 07:51:38 pm

Title: [SOLVED] SynEdit print
Post by: Pe3s on August 15, 2022, 07:51:38 pm
Hello forum members, how do I have to complete the code to print the SynEdit content
Code: Pascal  [Select][+][-]
  1. if PrintDialog1.Execute then
  2. begin
  3. SynEdit ??
  4. end;
Title: Re: SynEdit print
Post by: Martin_fr on August 15, 2022, 08:13:59 pm
This doesn't currently exist.



There is somewhere some code for html export.  (The Ide uses this)
Based on that code you could write a printer function.

It may also be possible to subclass, and access
Code: Pascal  [Select][+][-]
  1.     FPaintArea.Paint(Canvas, rcClip);
But you would also need to setup the current topline, width, height, .... and add line wrapping if needed (there is an addon in the synedit folder)
Title: Re: SynEdit print
Post by: Handoko on August 15, 2022, 08:16:01 pm
Use TSynEdit.PaintTo.

More info:
https://wiki.lazarus.freepascal.org/Using_the_printer#Advanced_steps:_printing_controls
Title: Re: SynEdit print
Post by: Bart on August 15, 2022, 09:48:40 pm
If you are on Windows:
Export as HTML (Use a TSynExporterHTML for that, itá on the SynEdit Tab in the IDE)
Call ShelExecute with the 'print' verb on that HTML file.

Bart
Title: Re: SynEdit print
Post by: simone on August 15, 2022, 11:36:13 pm
Some time ago I made a simple text editor based on SynEdit component. I share the the code to print text excerpted from that program. The following procedure handles printing on multiple pages when necessary. I hope it will be useful for your purposes.

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.Print(Sender: TObject);
  2. //CurrSynEdit is the istance of TSynEdit with the text to print
  3. var
  4.   YPos, LineHeight, HorizontalMargin, VerticalMargin: Integer;
  5.   Line : string;
  6. begin
  7.   if PrintDialog.Execute then
  8.     with Printer do
  9.       try
  10.         BeginDoc;
  11.         Canvas.Font.Name:='Courier New';
  12.         Canvas.Font.Size:=10;
  13.         Canvas.Font.Color:=clBlack;
  14.         LineHeight:=Round(1.2*Abs(Canvas.TextHeight('I')));
  15.         VerticalMargin:=4*LineHeight;
  16.         HorizontalMargin:=VerticalMargin;
  17.         YPos:=VerticalMargin;
  18.         for Line in CurrSynEdit.Lines do
  19.           begin
  20.             Canvas.TextOut(HorizontalMargin,YPos,Line);
  21.             Inc(YPos,LineHeight);
  22.             if YPos>PageHeight-VerticalMargin then
  23.               begin
  24.                 YPos:=VerticalMargin;
  25.                 NewPage;
  26.               end;
  27.           end;
  28.       finally
  29.         EndDoc;
  30.       end;
  31. end;
Title: Re: SynEdit print
Post by: Pe3s on August 16, 2022, 07:58:47 pm
Thanks to everyone for the answers :)
TinyPortal © 2005-2018