Page 1 of 1

How can i save the PageSetup settings into my document?

Posted: Tue Oct 18, 2005 8:33 am
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

Posted: Tue Oct 18, 2005 12:39 pm
by Sergey Tkachenko
Use DocProperties property.

Posted: Tue Oct 18, 2005 6:21 pm
by Fellow
Is DocProperties property a user custom data storer?

Posted: Tue Oct 18, 2005 9:19 pm
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

Posted: Wed Oct 19, 2005 1:27 am
by Fellow
Thx!
THat's a powerful property.

If there is another property storing binary structures, it would be excellent.

Posted: Wed Oct 19, 2005 8:39 am
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.