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.
RV Header/Footer in HTML
-
- Site Admin
- Posts: 17555
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
1) You can create HTML from several HTMLs
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:
rv must be linked to its own TRVStyle.
Code: Select all
rvMain.SaveHTMLToStreamEx(...[rvsoFirstOnly])
rvHeader.SaveHTMLToStreamEx(...[rvsoMiddleOnly])
rvMain.SaveHTMLToStreamEx(...[rvsoMiddleOnly])
rvFooter.SaveHTMLToStreamEx(...[rvsoMiddleOnly])
rvMain.SaveHTMLToStreamEx(...[rvsoLastOnly])
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(...)
I have not the problem of saving documents as HTML and am doing it this way:
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.
Code: Select all
saveOptions := [rvsoInlineCSS, rvsoOverrideImages];
Editor.SaveHTMLEx(appPath + 'TempFiles\HTMLExportDoc.htm', 'Document', 'HTMLExportDoc.Files\docImg', '', '', '', saveOptions);
Upon exporting i don´t get the header and footer exported with it and i don´t know how to get them manually.
-
- Site Admin
- Posts: 17555
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
To make clear where i need it:
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.
Code: Select all
procedure TsrvActionsResource.TestActionEventExecute(Sender: TObject; Editor: TCustomRichViewEdit);
begin
// Here i need the Header and Footer of the Editor.
end;
How exactly can i access header and footer of the editor in this case.
-
- Site Admin
- Posts: 17555
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Here is an example.
It implements the simplest way - assembling a temporal document in invisible TRichView.
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:(or you can make these assignments at designtime in the Object Inspector)
2) Use TRVAControlPanel.OnCustomFileOperation event
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;
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';
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;