Recent

Author Topic: [SOLVED] SynEdit print  (Read 803 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 533
[SOLVED] SynEdit print
« 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;
« Last Edit: August 16, 2022, 07:59:02 pm by Pe3s »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit print
« Reply #1 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)

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: SynEdit print
« Reply #2 on: August 15, 2022, 08:16:01 pm »

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: SynEdit print
« Reply #3 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

simone

  • Hero Member
  • *****
  • Posts: 573
Re: SynEdit print
« Reply #4 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;
« Last Edit: August 16, 2022, 09:06:48 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: SynEdit print
« Reply #5 on: August 16, 2022, 07:58:47 pm »
Thanks to everyone for the answers :)

 

TinyPortal © 2005-2018