How can i save the PageSetup settings into my document?

General TRichView support forum. Please post your questions here
Post Reply
Fellow

How can i save the PageSetup settings into my document?

Post by Fellow »

Some of my documents must have special page settings, like MarginLeft, MarginTop, etc.
But i can't find the way to save them.

How?
Waiting for answers
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Use DocProperties property.
Fellow

Post by Fellow »

Is DocProperties property a user custom data storer?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Yes. I found my old e-mail with explanations how to modify the ActionTest demo to save margins in RVF. It is quoted below.

1) Include rvfoSaveDocProperties and rvfoLoadDocProperties in
RichViewEdit1.RVFOptions
2) Write two procedures for saving and loading headers and footers (and RVPrint margins):

Code: Select all

procedure TForm3.LoadDocProps;
var s: String;
begin
  with RichViewEdit1.DocProperties do begin
    RVA_HeaderInfo.Text := Values['HeaderText'];
    RVA_FooterInfo.Text :=  Values['FooterText'];
    RVA_HeaderInfo.Alignment := TAlignment(StrToIntDef(Values['HeaderAlign'],0));
    RVA_FooterInfo.Alignment := TAlignment(StrToIntDef(Values['FooterAlign'],0));
    RVA_HeaderInfo.PrintOnFirstPage := StrToIntDef(Values['HeaderFP'],1)<>0;
    RVA_FooterInfo.PrintOnFirstPage := StrToIntDef(Values['FooterFP'],1)<>0;
    s := Values['LeftMarginMM'];
    RVPrint1.LeftMarginMM := StrToIntDef(s, 20);
    s := Values['TopMarginMM'];
    RVPrint1.TopMarginMM := StrToIntDef(s, 20);
    s := Values['RightMarginMM'];
    RVPrint1.RightMarginMM := StrToIntDef(s, 20);
    s := Values['BottomMarginMM'];
    RVPrint1.BottomMarginMM := StrToIntDef(s, 20);
  end;
end;
 
procedure TForm3.SaveDocProps;
begin
  with RichViewEdit1.DocProperties do begin
    Clear;
    Add('HeaderText='+RVA_HeaderInfo.Text);
    Add('FooterText='+RVA_FooterInfo.Text);
    Add('HeaderAlign='+IntToStr(Ord(RVA_HeaderInfo.Alignment)));
    Add('FooterAlign='+IntToStr(Ord(RVA_FooterInfo.Alignment)));
    Add('HeaderFP='+IntToStr(Ord(RVA_HeaderInfo.PrintOnFirstPage)));
    Add('FooterFP='+IntToStr(Ord(RVA_FooterInfo.PrintOnFirstPage)));
    Add('LeftMarginMM='+IntToStr(RVPrint1.LeftMarginMM));
    Add('TopMarginMM='+IntToStr(RVPrint1.TopMarginMM));
    Add('RightMarginMM='+IntToStr(RVPrint1.RightMarginMM));
    Add('BottomMarginMM='+IntToStr(RVPrint1.BottomMarginMM));
  end;
end;
3) Now you need to update docproperties when page properties are changes.
In new version of RichViewActions, you can use rvActionPageSetup.OnChange event (simply call SaveDocProps there)
In older version of RichViewActions, use OnExecute:

First call default Execute (showing dialog), then save changes in
RichViewEdit1.DocProperties:

Code: Select all

procedure TForm3.rvActionPageSetupExecute(Sender: TObject);
begin
  (Sender as TrvActionPageSetup).OnExecute := nil;
  (Sender as TrvActionPageSetup).Execute;
  (Sender as TrvActionPageSetup).OnExecute := rvActionPageSetupExecute;
  RichViewEdit1.Change;
  SaveDocProps
end;
4) Process rvActionSave.OnDocumentFileChange
(this event is already processed in the ActionTest demo)

Code: Select all

procedure TForm3.rvActionSave1DocumentFileChange(Sender: TObject;
  Editor: TCustomRichViewEdit; const FileName: String;
  FileFormat: TrvFileSaveFilter; IsNew: Boolean);
begin
  ....
  LoadDocProps;
end;
It also possible to save this information to RTF (using OnSaveRTFExtra), but not possible to read

Fixed: the line "s := Values['LeftMarginMM'];" is added
Last edited by Sergey Tkachenko on Wed Oct 19, 2005 12:37 pm, edited 1 time in total.
Fellow

Post by Fellow »

Thx!
THat's a powerful property.

If there is another property storing binary structures, it would be excellent.
jonjon
Posts: 467
Joined: Sat Aug 27, 2005 4:19 pm

Post by jonjon »

Fellow wrote:If there is another property storing binary structures, it would be excellent.
Well, I don't know if there is but you could still convert your binary data to a Base64 encoded string.

Regards,
John.
Post Reply