Export of RichView Content to HTML
|Top Previous Next|
TRichView has methods for saving HTML files. There are no methods for reading HTML files in current version (use free add-ons: TrvHtmlImporter and TrvHtmlViewImporter).
TRichView saves HTML file and a set of image files.
By default, images are saved as Jpegs (*.jpg).
If you do not want to use TJpegImage class, you can define RVDONOTUSEJPEGIMAGE conditional define when compiling, and images will be saved as bitmaps.
You can specify graphic formats that must not be converted to Jpegs using RVGraphicHandler.RegisterHTMLGraphicFormat. TRichView itself define PNG (TPngImage, Delphi 2009+) and GIF (TGifImage, Delphi 2007+) as HTML graphic formats.
There are two ways to save HTML in RichView:
▪saving using <font>, <b>, <i> and similar html tags,
▪saving using CSS (Cascading Style Sheets).
HTML files which were saved with the first way can be read by larger number of programs (including TrvHtmlImporter).
HTML files with CSS retain much more formatting properties of TRichView document (they look almost exactly like TRichView content when using a capable browser) and have much more elegant and compact HTML code. TRVHtmlImporter does not support CSS generally, but it can read HTML with CSS files saved by TRichView.
Saving Using <font> Tags
function RichView.SaveHTML(const FileName,Title,
ImagesPrefix: String; Options: TRVSaveOptions):Boolean;
FileName – file name.
Title – title of document (tag <title>).
Return value – "saving was successful?"
ImagesPrefix – first part of images file names. For example, if ImagesPrefix='img' then images will be saved as img1.jpg, img2.jpg and so on (or img1.bmp, img2.bmp and so on, see above).
If rvsoOverrideImages in Options then all files with the same names will be overridden. Otherwise, the component will make unique file names for images.
Saved jpegs or bitmaps are not transparent. When converting to jpeg or bitmap, transparent color of icons or metafiles converted to the background color of RichView.
Checkpoints are saved as <a name=RichViewCheckpoint#></a> where # is an index of checkpoint. If rvsoUseCheckpointsNames is in Options, checkpoint name is used instead.
RichView uses Charset property of 0th text style to save language of HTML file (for Delphi 3+). There is also an option to save Unicode (UTF-8) HTML files.
When saving with SaveHTML method, many formatting properties are lost (such as text and paragraph background colors, borders, hover color, all margins/indents, font sizes are converted to 7 available HTML font sizes). Centered and stretched background bitmaps become tiled.
Saving Using CSS
function RichView.SaveHTMLEx(const FileName, Title, ImagesPrefix,
ExtraStyles, ExternalCSS, CPPrefix: String;
This method is not an extension of SaveHTML method – this is a completely different method. It saves HTML using style sheets (CSS). CSS can be saved inside HTML file or this method can place only a reference to external CSS file into this HTML file
External CSS file can be saved using SaveCSS method of RichView.Style:
You can save your style sheet one time and use it for all saved HTML files (if they all use the same collection of styles). This method allows you to reduce size when saving several HTML files with the same text and paragraph styles.
Font families are stored in CSS for the most frequently used fonts. For example, if font name is 'Arial', the string 'Arial', 'Helvetica', sans-serif will be saved.
ExtraStyles is a string that can contain additional styles for your own use. RichView will not use these styles, but you can use them when saving, for example, controls and URLs.
CPPrefix is a first part of name used when saving checkpoint. If CPPrefix='' then RichView uses standard name ('RichViewCheckPoint'). For example, if CPPrefix='label' then checkpoints will be saved as <a name=label#></a> where # is an index of checkpoint. If rvsoUseCheckpointsNames is in Options, checkpoint name is used instead.
Usually you do not need to use advanced parameters and can write:
MyRichView.SaveHTMLEx(MyFileName, MyTitle, MyImagesPrefix,
'', '', '', );
Saved HTML looks exactly like TRichView with the exceptions:
▪if VShift property of text style >0 then this style saved as superscript, <0 as subscript;
▪only "normal" (not "hot") hotspots' pictures are saved;
▪border styles converted to available set for HTML;
▪negative BorderOffsets can be saved, but browsers understand them as zero offsets;
▪paragraph background offsets and border offsets can't be saved separately; maximal values of these offsets are saved.
Common for the Both Methods
By default, inserted controls are not saved. However, you can save them in the event OnSaveComponentToFile.
You can insert HTML codes in text.
You can completely change saving of items of any type in HTML using OnSaveItemToFile event.
There is also a possibility to save only part of HTML document (opening part, middle part, closing part) – useful if you use HTML output of RichView only as a part of HTML document.
SaveHTMLEx saves all text of "Symbol" and "Wingdings" fonts as a set of HTML character entities or Unicode codes. For example, the text 'a+b=g' of "Symbol" font (α+β=γ) is saved as 'α+β=γ'
▪correct view modern browsers (not only in IE);
▪correct view on non-Windows platforms
▪characters may look slightly different;
▪some exotic characters are lost.
Headers and footers
Numeration of checkpoints starts from 0 in each table cell. So, it's recommended to use checkpoint names as identifiers (add rvsoUseCheckpointsNames in Options).
▪Example how to save MIME-encoded files (*.eml or *.mht), how to send HTML e-mail using TNMSMTP or TIdSMTP components: http://www.trichview.com/forums/viewtopic.php?t=11.
TRichView © trichview.com