Export Header/Footer to RTF

General TRichView support forum. Please post your questions here
Sergey Tkachenko
Site Admin
Posts: 17606
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Not yet, but this will be the next feature to implement.
Sergey Tkachenko
Site Admin
Posts: 17606
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Finally, TRichView can save formatted headers and footers in RTF. Update is uploaded for registered users.
josemaria
Posts: 5
Joined: Thu Jul 24, 2008 4:42 pm
Location: Spain

different header/sections in version 11?

Post by josemaria »

Hi,
Please, do you have an example for different headers?
I have a complex project that needs multiples headers/sections and I have waiting for a solution to this problem in RTF generation.
I am waiting more than a year for it. Please, tell me that it's solved, and an example. :shock:
Last edited by josemaria on Wed Jul 08, 2009 12:10 pm, edited 1 time in total.
Sergey Tkachenko
Site Admin
Posts: 17606
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If you have header in RichViewH, footer in RichViewF, then saving RTF with header:

Code: Select all

RichView1.Options := RichView1.Options+[rvrtfSaveHeaderFooter];
RichView1.RTFReadProperties.SetHeader(RichViewH.RVData);
RichView1.RTFReadProperties.SetFooter(RichViewF.RVData);
RichView1.SaveRTF(...);
josemaria
Posts: 5
Joined: Thu Jul 24, 2008 4:42 pm
Location: Spain

Post by josemaria »

Thanks.
I will tray it, but, also, I need multiple sections with different headers.
Mi application generates first one RichViewEdit text from a lot of data, and need to export it to RTF and/or DOC file, with multiple sections, any with different header and different page numbers, at less in the RTF file, that is the final task of my application. If no, the RTF must to be processed one and another time with one word processor.
:?
Sergey Tkachenko
Site Admin
Posts: 17606
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I am sorry, saving headers and footers for sections is not supported.
josemaria
Posts: 5
Joined: Thu Jul 24, 2008 4:42 pm
Location: Spain

Post by josemaria »

Sergey Tkachenko wrote:Finally, TRichView can save formatted headers and footers in RTF. Update is uploaded for registered users.
A. Does include it page numbers?
It is basic for headers/footers.
B. I have tried the CreateRTFWithSections example. It is possible generation of RTF with sections without RTF files, directly with richview editors?.
C. It is possible merging of RTF files in one file so that it include the different headers from the separated RTF files?
D. I think actually we have two different ways:
1. Headers/footers via RV1.RTFReadProperties.SetHeader(RV1H.RVData) (formated, but no page numbers?)
2. Headers/footers via OnSaveRTFExtra and RTFCode (page numbers, but limited and complicated format options)
It is possible that the two ways joint in one way?
Anything similar happens with doc properties
I think this questions are the more complicated themes about RichView
Do you can make a document that resume and clarifies it?
Thank you for your fast replays.
Sergey Tkachenko
Site Admin
Posts: 17606
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

A. If you want to include page number in RTF, you need to insert the following RTF code in the document (header or footer):
{\field{\*\fldinst PAGE}{\fldrslt 1}}
There are two ways how to insert RTF code in document, see http://www.trichview.com/forums/viewtopic.php?t=2742 . This example inserts different RTF code, but the idea is the same.

B. Of course. Instead of inserting from TFileStream, create TMemoryStream, save in it, then insert.

C. Merging RTF file is not easy. RTF file has tables of colors, fonts, lists, etc. (one table of each type in a file). You cannot just take a fragment of RTF code from one file and insert in another, because it refers to different tables.
josemaria
Posts: 5
Joined: Thu Jul 24, 2008 4:42 pm
Location: Spain

Post by josemaria »

Sergey Tkachenko wrote: B. Of course. Instead of inserting from TFileStream, create TMemoryStream, save in it, then insert.
From the CreateRTFWithSections example procedure:

Code: Select all

procedure CreateRTFWithSections(RVFFiles: array of String;
  const RTFFile: String; rv: TCustomRichView);
var i: Integer;
  Stream: TFileStream;
  ...
  for i := Low(RVFFiles) to High(RVFFiles) do
    try
      Stream := TFileStream.Create(RVFFiles[i], fmOpenRead);
      try
        rv.InsertRVFFromStream(Stream, rv.ItemCount);
        if i<>High(RVFFiles) then
          rv.AddNL('\sect\pgnrestart', 1, 0);
      finally
        Stream.Free;
      end;
    except
      rv.AddNL('Error loading file', 0, 0);
    end;
I changed for:

Code: Select all

procedure CreateRTFWithSections2(RVFFiles: array of TRichViewEdit;
  const RTFFile: String; rv: TCustomRichView);
var i: Integer;
  MStream: TMemoryStream;
...      
  for i := Low(RVFFiles) to High(RVFFiles) do
    try
      MStream := TMemoryStream.Create;
      RVFFiles[i].SaveRVFToStream(MStream, False);
      try
        rv.InsertRVFFromStream(MStream, rv.ItemCount);
        if i<>High(RVFFiles) then
          rv.AddNL('\sect\pgnrestart', 1, 0);
      finally
        MStream.Free;
      end;
    except
      rv.AddNL('Error loading file', 0, 0);
    end;
It makes an empty rv file.
Please, help me! :(
Thank you
Sergey Tkachenko
Site Admin
Posts: 17606
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Add:

Code: Select all

Stream.Position := 0;
after calling SaveRVFToStream.
Post Reply