[Example] Saving additional information in RTF files (and in DocX too)
Posted: Tue Sep 06, 2005 5:47 pm
Use OnSaveRTFExtra event:
Saving margins
Note: since TRichView v10, you can save and load margins specified in DocParameters.
Saving plain text header and footer
In this example:
\posxc - keyword for aligning header/footer to center
\posxr - keyword for aligning header/footer to right
{\field{\*\fldinst PAGE}{\fldrslt 1}} - code for inserting page number
Note: since TRichView v11, you can save and load header and footer in other richviews, see rvrtfSaveHeaderFooter in RTFOptions
Saving margins
Code: Select all
procedure TForm3.RichViewEdit1SaveRTFExtra(Sender: TCustomRichView;
Area: TRVRTFSaveArea; Obj: TObject; Index1, Index2: Integer;
InStyleSheet: Boolean; var RTFCode: TRVUnicodeString);
function MMToTwips(mm: Integer): Integer;
begin
Result := Round(mm*1440*5/127);
end;
begin
// uncomment "AnsiStrings." if you use Delphi 2009+
if Area=rv_rtfs_Doc then
RTFCode := {AnsiStrings.}Format('\margl%d\margt%d\margr%d\margb%d',
[MMToTwips(RVPrint1.LeftMarginMM),
MMToTwips(RVPrint1.TopMarginMM),
MMToTwips(RVPrint1.RightMarginMM),
MMToTwips(RVPrint1.BottomMarginMM)]);
end;
Saving plain text header and footer
Code: Select all
procedure TForm3.RichViewEdit1SaveRTFExtra(Sender: TCustomRichView;
Area: TRVRTFSaveArea; Obj: TObject; Index1, Index2: Integer;
InStyleSheet: Boolean; var RTFCode: TRVUnicodeString);
begin
if Area=rv_rtfs_Doc then
RTFCode :=
'{\header\pard\plain\posxc THIS IS HEADER WITH PAGENUMBER: {\field{\*\fldinst PAGE}{\fldrslt 1}}\par}'+
'{\footer\pard\plain\posxr THIS IS FOOTER\par}';
end;
\posxc - keyword for aligning header/footer to center
\posxr - keyword for aligning header/footer to right
{\field{\*\fldinst PAGE}{\fldrslt 1}} - code for inserting page number
Note: since TRichView v11, you can save and load header and footer in other richviews, see rvrtfSaveHeaderFooter in RTFOptions