Article Details
Id:21969
Product:finPOWER Connect
Type:NEW
Version:6.00.00
Opened:23/12/2024
Closed:03/02/2025
Released:17/04/2025
Job: J034907

Word Documents; new function LoadFromHtmlString added

A new function LoadFromHtmlString has been added to ISWordDocument. This allows a simple HTML String to be loaded as the Word Document.

Note, the Word Document may look different from the HTML when loaded on to a web page. This may be because of the Page layout, but also because some complex display options and JavaScript rendering are not supported. Also, HTML structure is more flexible than Word structure, so it is not always possible to convert HTML to Word directly.

The following meta tags can be included in the HTML to specify load options and to modify the Page Layout:

  • <meta name='html-BaseAddress' content='https://example.com/'/>
    • The base address for images with a relative location.
    • Replace 'https://example.com/' with your relative path.
    • For example, an image with relative location <img src="Pictures/MyPicture.jpg"/> will use the base location specified.
  • <meta name='pdf-PageSize' content='A2|A3|A4|A5|A6|Legal|Letter'/>
    • Defines the Page Size.
    • If not specified, or invalid, A4 is used.
  • <meta name='pdf-PageOrientation' content='Landscape|Portrait'/>
    • Defines the Page Orientation.
  • <meta name='pdf-LeftMargin' content='99cm|99in|99px|99pt'/>
    • The Page's Left Margin.
    • This can be specified in either cm (centimetres), in (inches), px (pixels) or pt (points). If not specified points are assumed.
  • <meta name='pdf-RightMargin' content='99cm|99in|99px|99pt'/>
    • The Page's Right Margin.
    • This can be specified in either cm (centimetres), in (inches), px (pixels) or pt (points). If not specified points are assumed.
  • <meta name='pdf-TopMargin' content='99cm|99in|99px|99pt'/>
    • The Page's Top Margin.
    • This can be specified in either cm (centimetres), in (inches), px (pixels) or pt (points). If not specified points are assumed.
  • <meta name='pdf-BottomMargin' content='99cm|99in|99px|99pt'/>
    • The Page's Bottom Margin.
    • This can be specified in either cm (centimetres), in (inches), px (pixels) or pt (points). If not specified points are assumed.

An example code snippet is shown below.

Dim Document As ISWordDocument
Dim Html As String

Html="<!DOCTYPE html>
<html>
<meta name='pdf-PageOrientation' content='Landscape'>
<meta name='pdf-LeftMargin' content='2cm'>
<body>
<h1>First Heading</h1>
<p>First paragraph.</p>
</body>
</html>"

Document = finBL.CreateWordDocument()

With Document
  If .LoadFromHtmlString(Html) Then
    ' Save as Word Document
    .Save("Document.docx")

    ' Save as PDF Document
    .Save("Document.pdf")
  Else
    ' Error
  End If  
End With