How to print the content of a RichViewEdit ?
Posted: Fri Mar 08, 2024 9:42 am
Hi,
With a TRichEdit, I use this code :
///////////////////////////////////////////////////////////////////
RE is the RichEdit
var Range : TFormatRange;
SaveRect: TRect;
TextLenEx: TGetTextLengthEx;
LastChar, MaxLen : integer;
/////////////////////////////// printing code
FillChar(Range, SizeOf(TFormatRange), 0);
with Range
do begin
hdc := tiPrinter.Canvas.Handle;
hdcTarget := tiPrinter.Canvas.Handle;
// a particular area on the sheet defined here /// MultDiv(a, b, c) = (a * b) div c
RC.Top := MultDiv(yTop, TwipsPerInch, tiPrintCaps.YPixelsPerInch);
RC.Left := MultDiv(xLeft, TwipsPerInch, tiPrintCaps.XPixelsPerInch);
RC.Bottom := MultDiv(yBottom, TwipsPerInch, tiPrintCaps.YPixelsPerInch);
RC.Right := MultDiv(xRight, TwipsPerInch, tiPrintCaps.XPixelsPerInch);
rcPage := RC;
SaveRect := RC;
end;
LastChar := 0;
with TextLenEx
do begin
Flags := GTL_DEFAULT;
codepage := CP_ACP;
end;
MaxLen := RE.Perform(EM_GETTEXTLENGTHEX, WParam(@TextLenEx), 0);
Range.chrg.cpMax := -1;
repeat
Range.RC := SaveRect;
Range.chrg.cpMin := LastChar;
LastChar := SendMessage(RE.Handle, EM_FORMATRANGE, 1, Longint(@Range));
{
if (LastChar < MaxLen) and (LastChar <> -1) then
NewPage; }
until (LastChar >= MaxLen) or (LastChar = -1);
SendMessage(RE.Handle, EM_FORMATRANGE, 0, 0); { flush buffer }
/////////////////////////////////////////////////////////////////////////
This code works fine. But how to proceed with TRichViewEdit ? Because if I only change from RE to RVE, nothing is printed.
Thank you
With a TRichEdit, I use this code :
///////////////////////////////////////////////////////////////////
RE is the RichEdit
var Range : TFormatRange;
SaveRect: TRect;
TextLenEx: TGetTextLengthEx;
LastChar, MaxLen : integer;
/////////////////////////////// printing code
FillChar(Range, SizeOf(TFormatRange), 0);
with Range
do begin
hdc := tiPrinter.Canvas.Handle;
hdcTarget := tiPrinter.Canvas.Handle;
// a particular area on the sheet defined here /// MultDiv(a, b, c) = (a * b) div c
RC.Top := MultDiv(yTop, TwipsPerInch, tiPrintCaps.YPixelsPerInch);
RC.Left := MultDiv(xLeft, TwipsPerInch, tiPrintCaps.XPixelsPerInch);
RC.Bottom := MultDiv(yBottom, TwipsPerInch, tiPrintCaps.YPixelsPerInch);
RC.Right := MultDiv(xRight, TwipsPerInch, tiPrintCaps.XPixelsPerInch);
rcPage := RC;
SaveRect := RC;
end;
LastChar := 0;
with TextLenEx
do begin
Flags := GTL_DEFAULT;
codepage := CP_ACP;
end;
MaxLen := RE.Perform(EM_GETTEXTLENGTHEX, WParam(@TextLenEx), 0);
Range.chrg.cpMax := -1;
repeat
Range.RC := SaveRect;
Range.chrg.cpMin := LastChar;
LastChar := SendMessage(RE.Handle, EM_FORMATRANGE, 1, Longint(@Range));
{
if (LastChar < MaxLen) and (LastChar <> -1) then
NewPage; }
until (LastChar >= MaxLen) or (LastChar = -1);
SendMessage(RE.Handle, EM_FORMATRANGE, 0, 0); { flush buffer }
/////////////////////////////////////////////////////////////////////////
This code works fine. But how to proceed with TRichViewEdit ? Because if I only change from RE to RVE, nothing is printed.
Thank you