I'm trying to insert an RTF element from our application into a wider HTML output. I'm using the RichViewEdit.SaveHTMLEX (18.01) to try and do this.
I'm using a Bootstrap CSS for the output in general, but wanted to override locally for the RTF, so I used Middle Only and Inline CSS options on the SaveHTMLEX. However, it's not picking up the CSS properties for things like form size, background colour, text colour, text decoration etc.
I've tried it from the demo application and it works great, so I know it's something I'm doing.
My code for converting RTF to HTML looks like this:
Code: Select all
function TfrmSTShellSheet.RTFToHTML(aRTF: TSTDBRTFEdit; aName: string): string;
var
oRTF : TRichViewEdit;
oStyle : TRVStyle;
oHTML : TStringList;
sRTFFile : string;
sHTMLFile: string;
begin
Result := '';
if Length(aRTF.RTFText) = 0 then
exit;
sRTFFile := HTMLTempRTFFile(aName);
sHTMLFile := HTMLTempHTMLFile(aName);
oRTF := TRichViewEdit.Create(sfpMain);
oStyle := TRVStyle.Create(sfpMain);
try
oRTF.Visible := False;
oRTF.Parent := sfpMain;
oRTF.Style := oStyle;
// Shift the RTF into a file to be loaded into RVEdit
aRTF.SaveTerFile(sRTFFile);
oRTF.Clear;
oRTF.LoadRTF(sRTFFile);
oRTF.Format;
// Save the middle section with inline CSS
oRTF.SaveHTMLEx(sHTMLFile, aName, 'img' + fsHTMLFileName + aName, '', '', '', [rvsoInlineCSS, rvsoMiddleOnly]);
// Load it into a string list to include in the wider page
oHTML := TStringList.Create;
try
oHTML.LoadFromFile(sHTMLFile);
Result := oHTML.Text;
finally
oHTML.Free;
DeleteFile(PChar(sHTMLFile));
end;
finally
oRTF.Free;
end;
end;
Code: Select all
<p style="text-align: left; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px;"><span style=" font-size: 10pt; font-family: 'Arial', 'Helvetica', sans-serif; font-style: normal; font-weight: normal; color: #000000; background-color: transparent; text-decoration: none;">This text is larger and in red.</span></p>
<p style="text-align: left; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px;"><span style=" font-size: 10pt; font-family: 'Arial', 'Helvetica', sans-serif; font-style: normal; font-weight: normal; color: #000000; background-color: transparent; text-decoration: none;">Background is pale pink</span></p>