// -----------------------------------------------------------------------------
// GLOBAL: - FFrameRect
// - RE_PAGE
// - RE_SRC
procedure TMainForm.RenderRichEdit(Files : TStringList);
procedure RenderPage();
var
TextRect: TRect;
Offset: Integer;
begin
Offset := 0;
while (Offset >= 0)
and
(PrintPreview.PaintRichText(FFrameRect, RE_Page, 1, @Offset) <> 0)
do
begin
Application.ProcessMessages;
if (Offset >= 0)
then PrintPreview.NewPage;
end;
end;
var
SS : TStringStream;
MS : TMemoryStream;
RTFplain : ANSIString;
// should be NOT a wide string !!!
i, l, p : integer;
begin
PrintPreview.BeginDoc;
PrintPreview.Units := mmHiMetric;
// All units are in 1/100th of millimeter
CalcFrame;
// ... loop the files
for I := 1
to Files.Count
do
begin
SS := TStringStream.Create('
');
MS := TMemoryStream.Create;
RE_SRC.Clear;
RE_PAGE.Clear;
// ... load file to stream and copy to ANSI-STRING !!! (NOT WIDE)
SS.LoadFromFile(Files[i-1]);
SetLength(RTFplain, SS.Size);
SS.
Read(RTFplain[1], SS.Size);
// - replace \page(bb) with ' |NEWPAGE|' as readable text for FORMFEED
RTFplain := StringReplace(RTFplain, '
\pagebb', '
|NEWPAGE|', [rfReplaceAll]);
// RTFplain := StringReplace(RTFplain, '\page', ' |NEWPAGE|', [rfReplaceAll]);
MS.Position := 0;
MS.WriteBuffer(RTFplain[1],Length(RTFplain));
// load back to stream
MS.Position := 0;
RE_SRC.Lines.LoadFromStream(MS);
// load back to RTF-Source
SS.Free;
// ... now look for the new placeHolder(s)
repeat
MS.Clear;
// ... copy source-RTF to print-RTF | RE_PAGE := RE_SRC DOESN'T WORK !!!
RE_SRC.Lines.SaveToStream(MS);
MS.Position := 0;
RE_PAGE.Lines.LoadFromStream(MS) ;
// ... search placeholder
l := RE_SRC.GetTextLen;
p := RE_SRC.FindText('
|NEWPAGE|', 0, l, [stMatchCase]);
if (p > -1)
then
begin // ... found it
RE_PAGE.Lines.BeginUpdate;
// DELETE text after placeholder in print
RE_PAGE.SelSTart := p;
RE_PAGE.SelLength := l - p;
RE_PAGE.SetSelText('
');
RE_PAGE.Lines.EndUpdate;
RE_SRC.Lines.BeginUpdate;
// DELETE text upto/incl. placeholder in source
RE_SRC.SelSTart := 0;
RE_SRC.SelLength := p + 9;
RE_SRC.SetSelText('
');
RE_SRC.Lines.EndUpdate;
RenderPage;
//RenderRichEdit; // Render print-RTF
PrintPreview.NewPage;
// DON'T FORGET !
end;
until (p < 0);
MS.Free;
RenderPage;
//RenderRichEdit; // Render rest of / complete print-RTF
end;
PrintPreview.EndDoc;
end;