[Example] How to combine several documents in one

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

[Example] How to combine several documents in one

Post by Sergey Tkachenko »

Code: Select all

procedure AddDoc(const FileName: String; rv: TCustomRichView);
var Stream: TFileStream;
begin
  Stream := TFileStream.Create(FileName, fmOpenRead);
  rv.InsertRVFFromStream(Stream, rv.ItemCount);
  Stream.Free;
end;

  ...

  RichView1.Clear;
  RichView1.DeleteUnusedStyles(True, True, True);
  AddDoc('c:\file1.rvf', RichView1);
  AddDoc('c:\file2.rvf', RichView1);
  AddDoc('c:\file3.rvf', RichView1);
  RichView1.Format;
If you want to add page breaks between documents, use the following code

Code: Select all

procedure AddDoc(const FileName: String; rv: TCustomRichView); 
var Stream: TFileStream; 
  ItemCount: Integer;
begin 
  ItemCount := rv.ItemCount;
  Stream := TFileStream.Create(FileName, fmOpenRead); 
  rv.InsertRVFFromStream(Stream, rv.ItemCount); 
  Stream.Free; 
  if (ItemCount>0)  and (ItemCount<rv.ItemCount) then
    rv.PageBreaksBeforeItems[ItemCount] := True;
end;
Last edited by Sergey Tkachenko on Fri Aug 24, 2007 5:12 pm, edited 1 time in total.
Guest

Post by Guest »

Hello Sergey,

How can I combine several RTFs into a single file - the example is only for RVFs & I cannot see any procedure like InsertRTFFromStream...

Thanks,

Fiachra
Guest

Post by Guest »

Don't worry about that question Sergey,

I've gotten around it by loading my RTFs (one at a time) into a RichView and saving them as RVFs which I then load as per your original example. It's a bit convoluted but it works!

Thanks anyway,

Fiachra
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It's not necessary. You can use LoadRTF/LoadRTFFromStream.
Unlike LoadRVF/LoadRVFFromStream they
- do not clear trichview,
- cannot replace collection of styles, they can only add new styles.

So you can use them to load several documents.
Post Reply