RV Header/Footer in HTML

General TRichView support forum. Please post your questions here
Post Reply
SpoQSI
Posts: 16
Joined: Wed Sep 02, 2015 11:48 am

RV Header/Footer in HTML

Post by SpoQSI »

Hello,

due to several reasons i need to save and work with richview documents as HTML.

I have a problem whith the export. Naturally the header and the footer are not exported to HTML.

My idea to solve that would be to copy the header and paste it to the beginning of the document, then copy the footer to the end of the document and export the whole thing as HTML.

Another idea would be to export the header and footer to HTML seperately and insert them manually in the HTML-exported document.

The problem with that idea is that i cant find a proper way of getting the header/footer.

Is there an easier way to achieve what i want to do? If not, how can i achieve the workaround, especially getting the header and footer of the document.

Greetings, and a happy new year, spoqsi.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

1) You can create HTML from several HTMLs

Code: Select all

rvMain.SaveHTMLToStreamEx(...[rvsoFirstOnly])
rvHeader.SaveHTMLToStreamEx(...[rvsoMiddleOnly])
rvMain.SaveHTMLToStreamEx(...[rvsoMiddleOnly])
rvFooter.SaveHTMLToStreamEx(...[rvsoMiddleOnly])
rvMain.SaveHTMLToStreamEx(...[rvsoLastOnly])
Since header, footer and the main document use different RVStyle objects, you cannot use the same CSS table for all these parts. You need to include rvsoInlineCSS in Options parameter of SaveHTMLToStreamEx.

2) Alternative solution - load all these parts in a single TRichView and save as HTML:

Code: Select all

Stream := TMemoryStream.Create;
rvHeader.SaveRVFToStream(Stream, False);
Stream.Position := 0;
rv.LoadRVFFromStream(Stream);
Stream.Clear;
rvMain.SaveRVFToStream(Stream, False);
Stream.Position := 0;
rv.InsertRVFFromStream(Stream, rv.ItemCount);
Stream.Clear;
rvFooter.SaveRVFToStream(Stream, False);
Stream.Position := 0;
rv.InsertRVFFromStream(Stream, rv.ItemCount);
Stream.Free;
rv.SaveHTMLEx(...)
rv must be linked to its own TRVStyle.
SpoQSI
Posts: 16
Joined: Wed Sep 02, 2015 11:48 am

Post by SpoQSI »

I have not the problem of saving documents as HTML and am doing it this way:

Code: Select all

saveOptions := [rvsoInlineCSS, rvsoOverrideImages];
Editor.SaveHTMLEx(appPath + 'TempFiles\HTMLExportDoc.htm', 'Document', 'HTMLExportDoc.Files\docImg', '', '', '', saveOptions);
I am using your ActionTestDemo where you got the whole document, including header and footer in one ScaleRichview.

Upon exporting i don´t get the header and footer exported with it and i don´t know how to get them manually.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I answered to the question, but I assumed that headers and footers are stored in separate editors (rvHeader and rvFooter).
Is this assumption wrong? How headers and footers in your applications defined?
SpoQSI
Posts: 16
Joined: Wed Sep 02, 2015 11:48 am

Post by SpoQSI »

As said, i used your ActionTest Demo (ScaleRichView) as basis and expanded it.

As far as i can tell, there you got a single ScaleRichViewEdit containing the whole Document, including Header and Footer.
SpoQSI
Posts: 16
Joined: Wed Sep 02, 2015 11:48 am

Post by SpoQSI »

To make clear where i need it:

Code: Select all

procedure TsrvActionsResource.TestActionEventExecute(Sender: TObject; Editor: TCustomRichViewEdit);
begin

// Here i need the Header and Footer of the Editor.

end;
This is a custom rv action added in your ActionTest Demo in the "ScaleRichView\Demos\ActionTest" Folder of your Examples.

How exactly can i access header and footer of the editor in this case.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Here is an example.

It implements the simplest way - assembling a temporal document in invisible TRichView.

Code: Select all

function TForm3.SaveHTMLWithHeaders(SRV: TSRichViewEdit; const FileName: String;
  Action: TrvActionExport): Boolean;
var
  Stream: TMemoryStream;
  rv: TRichView;
begin
  SRV.StartEditing(srvrveMain); // to make sure that header/footer is not being edited
  rv := TRichView.Create(nil);
  Stream := TMemoryStream.Create;
  try
    rv.Style := TRVStyle.Create(rv);
    // main document
    SRV.RichViewEdit.SaveRVFToStream(Stream, False);
    Stream.Position := 0;
    rv.LoadRVFFromStream(Stream);
    // header
    Stream.Clear;
    SRV.SubDocuments[srvhftNormalHeader].SaveRVFToStream(Stream, False,
      clNone, nil, nil, True);
    Stream.Position := 0;
    rv.InsertRVFFromStream(Stream, 0);
    // footer
    Stream.Clear;
    SRV.SubDocuments[srvhftNormalFooter].SaveRVFToStream(Stream, False,
      clNone, nil, nil, True);
    Stream.Position := 0;
    rv.InsertRVFFromStream(Stream, rv.ItemCount);
    // saving HTML
    rv.DeleteUnusedStyles(True, True, True);
    Result := rv.SaveHTMLEx(FileName, Action.FileTitle, Action.ImagePrefix,
      '', '', '', Action.SaveOptions);
  finally
    Stream.Free;
    rv.Free;
  end;
end;
This example saves only normal header and footer, headers and footers for the first page and even pages are ignored.

You can use this function to add a new item ('HTML with headers') in TrvActionExport dialog.
1) In FormCreate, call:

Code: Select all

  srvActionsResource.rvActionExport1.Filter :=
    srvActionsResource.rvActionExport1.Filter + [ffeCustom];
  srvActionsResource.rvActionExport1.CustomFilter := 'HTML with headers|*.htm;*.html';
(or you can make these assignments at designtime in the Object Inspector)

2) Use TRVAControlPanel.OnCustomFileOperation event

Code: Select all

procedure TForm3.RVAControlPanel1CustomFileOperation(Sender: TrvAction;
  Edit: TCustomRichViewEdit; const FileName: string;
  Operation: TRVAFileOperation; var SaveFormat: TrvFileSaveFilter;
  var CustomFilterIndex: Integer; var Success: Boolean);
begin
  if not (Sender is TrvActionExport) then
    exit;
  Success := SaveHTMLWithHeaders(
    TSRichViewEdit(Edit.RVData.GetScaleRichViewInterface.GetSRichViewEdit),
    FileName, TrvActionExport(Sender));
end;
Post Reply