Export of TRichView Content to HTML

<< Click to display table of contents >>

Export of TRichView Content to HTML

Overview

TRichView has methods for saving, loading, and inserting HTML files.

The following properties are used for HTML saving:

HTMLSaveProperties

DocParameters.Title and Comments.

Images

TRichView saves HTML file and a set of image files (alternatively, images may be embedded directly in HTML file).

Web image formats (like Gif or Png) are saved as they are. Other images are saved as Jpegs (*.jpg).

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.

Besides, you can save images yourself in custom formats using OnHTMLSaveImage or OnSaveImage2 event (see demo in Demos\*\Assorted\Save HTML\).

See also HTMLSaveProperties.ImageOptions, ImagesPrefix.

Two ways of HTML saving

There are two ways to save HTML in TRichView, defined HTMLSaveProperties.HTMLSavingType:

saving using <font>, <b>, <i> and similar html tags (rvhtmlstSimplified)

saving using CSS (Cascading Style Sheets) (rvhtmlstNormal)

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.

Checkpoints

Checkpoints are saved as anchors.

By default, names are checkpoints are used as names of anchors, but you can switch to generated anchor names.

See HTMLSaveProperties.UseCheckpointNames, CheckpointsPrefix.

Encoding

By default, TRichView creates UTF-8 HTML files.

UTF-8 is highly recommended, but you can change encoding using HTMLSaveProperties.Encoding property.

Saving Using CSS

By default, if HTMLSaveProperties.HTMLSavingType = rvhtmlstNormal, CSS is saved as a style sheet in the <head> part of HTML, and referred in tags using "class" attribute.

Alternatively, you can store a style sheet in an external file, and specify its name in HTMLSaveProperties.ExternalCSSFileName.

Alternatively, instead of using a style sheet, styles can be saved directly in HTML tags (using "style" attribute).

Even if HTML is generally saved without CSS (HTMLSaveProperties.HTMLSavingType = rvhtmlstSimplified), you can store non-text items (such as tables, images or horizontal lines) with CSS.

See HTMLSaveProperties.CSSOptions.

You can provide additional styles in HTMLSaveProperties.ExtraStyles.

Hyperlinks, controls, more...

By default, items tags are saved as targets of hypertext links. You can customize saving using the event OnWriteHyperlink.

By default, inserted controls are not saved. However, you can save them in the event OnSaveComponentToFile.

You can save additional information in HTML in the events: OnSaveHTMLExtra, OnSaveParaToHTML.

You can insert HTML codes in text.

You can completely change saving of items of any type in HTML using OnSaveItemToFile event.

You can save additional properties of non-text items using OnWriteObjectProperties event.

Symbol Fonts

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 '&alpha;+&beta;=&gamma;'

Pros:

correct view modern browsers (not only in IE);

correct view on non-Windows platforms

Cons:

characters may look slightly different;

some exotic characters are lost.

Headers and footers

If a header and/or a footer are defined, they can be saved before and after the main document in HTML. To do it, include rvsoHeaderFooter in the Options parameter of HTML saving methods.

The component uses either headers/footers for the first page or normal headers/footers, depending in TRichView.DocParameters.TitlePage.

Known problems:

Numeration of checkpoints starts from 0 in each table cell. So, it's recommended to use checkpoint names as identifiers (add rvsoUseCheckpointsNames in Options).

See also...

TRichView methods for saving and loading;

Export of tables;

Typed constants related to HTML export;

Example how to save MIME-encoded files (*.eml or *.mht), how to send HTML e-mail using TNMSMTP or TIdSMTP components: https://www.trichview.com/forums/viewtopic.php?t=11.