Promotic
WikipediaLinkedInYoutubeTwitterFacebook

SaveToHtm - method of object TrendsView

Description:
Method reads the HTML file specified by the sSrcHtm parameter, it modifies it by its own data exported into a string and creates the eventual HTML page that is saved according to setting the sDstHtm parameter.

Such created HTML page can be in the graph or table form and it can be used, for example, for printing (see Example1).

Syntax:
SaveToHtm(sSrcHtm As String, sDstHtm As String, sParams As String, [sParText As String]) As Variant
Calling:
b = oTView.SaveToHtm(sSrcHtm, sDstHtm, sParams)
Parameters:
sSrcHtm(String) Path to file (with path) defined with prefix file: (e.g. "file:c:/source.htm") from which the source HTML file is read. If a full path is not entered, it is completed relatively according to the application file folder (if the trends viewer runs in the PROMOTIC application).

If the entered value is:

ver:0 or empty string "" - the file suppiled together with the PROMOTIC system will be used. It is located in the Pmtrdvw2.dll library, meaning the old version wil be used.
ver:1 - meaning the new version 1 of internal source HTML file (TrPrintGraph1.htm) will be used. This is recommended.
In a web client, in a panel written with JavaScript language, the TrPrintGraph2.htm file will be used regardless on the setting.

In the Web subfolder of the PROMOTIC installation folder there can be found the equal template under the name TrPrintxxx.htm, where xxx differs whether it goes about the graph or table template - TrPrintGraph1.htm, TrPrintTable1.htm). This file can be copied (e.g. into the application folder), the copy can be modified and such modified copy can be used instead of the initial file by setting the sSrcHtm parameter to the path of this modified copy.

Macro expression cannot be used for direct input, but the EvalMacro method can be called.

sDstHtm(String) Location for saving the HTML page. It is either: It is either:
- disk file - File name of the HTML file (with the path) specified with the prefix file: (e.g. the "file:c:/dest.htm") that is newly created. If a full path is not entered, it is completed relatively according to the application file folder (if the trends viewer runs in the PROMOTIC application).
- string in variable (String) - In this case the parameter is of the input/output type (the input is "string:") and after calling the method it contains the contents of the HTML page.
- string in variable (String) - where "return:" is the keyword, then the method returns the content of the HTML page. (Method with this parameter is functional also in JavaScript panels.)

Macro expression cannot be used for direct input, but the EvalMacro method can be called.

sParams(String) Text list of parameters that define the way of creating the destination file. Entries with assigned value are separated by a semicolon, for example "mode:graph;view:dlg;".
"mode:xxx;" (optional) - Specifies which page is used for displaying the data of the trends viewer
table (default) - page in the table form
graph - page in the graph form of 2-dimensional graph
"graphcfg:xxx;" (optional) - Defines what setting is used for graphic trend viewer (TrendsView) in saved HTML page. The HTML page contains its own ActiveX object (TrendsView).
default (default) - All settings of the viewer in the saved HTML page will be default (except for from-until).
copy - All settings of the viewer in the saved HTML page will be taken from the viewer, that was called by the SaveToHtm method.
"view:xxx;" (optional) - Specifies whether and how the generated page has to be displayed
no (default) - is not displayed
dlg - generated page is displayed in the window with preset size
"text_xxx:yyy;" (optional) - HTML template (referred by the sSrcHtm parameter) contains several predefined keywords that allows to enter the user text, which appears in the final page (referred by the sDstHtm parameter) instead of the keyword, see the description of values.
text_title - Value of the keyword title from the HTML template (sSrcHtm) will be replaced by the string yyy.

Example: text_title:BoilerPlant 5;

text_note1 - Value of the keyword note1 from the HTML template (sSrcHtm) will be replaced by the string yyy.
text_note2 - Value of the keyword note2 from the HTML template (sSrcHtm) will be replaced by the string yyy.
text_codeinit - Value of the keyword codeinit from the HTML template (sSrcHtm) will be replaced by the string yyy. The yyy string is an initialization code in the javascript language that is run during reading the page.

If a char ; (semicolon) occurs in the yyy string, then text_codeinit:$Par:0; has to be set and the initialization code itself has to be set in the sParText parameter, see Example5. The oTView reference used in the example is the reference to the TrendsView trends viewer and his name must be kept.

text_userYY - Except the predefined keywords it is possible to edit the copy of the template (copied from the original HTML template from the PROMOTIC WEB folder, see the description of the sSrcHtm parameter) and to add next keywords in it and to define the string for replacement in this parameter. For example, if there is the keyword userkey in the HTML template, then the parameter is:

text_userkey:text for displaying;

sParText[optional] (String) Text for replacing the key word codeinit from the HTML template. See the description of the sParams parameter, the codeinit value.
Return Values:
true - saving proceeded successfully (not valid if the parameter sDstHtm = "return:")
false - otherwise (not valid if the parameter sDstHtm = "return:")
HTMLstring - Returns the html page content if the sDstHtm parameter is set to "return:"
"" - empty string ("") signals failure of the method (only if the sDstHtm parameter is set to "return:")
Example1:
Creation of graphic HTML page for printing in memory. In this case the HTML page suppiled with the PROMOTIC system is used as an empty template (source HTML file). Then it is possible to print the created HTML page using the default OS Windows printer and set the dimensions of the page.
 
VBScript
Dim sHtml
sHtml = oTView.SaveToHtm("ver:1", "return;", "mode:graph;")
If sHtml <> "" Then
  Pm.PrintHtmlPage sHtml, "sourcetype:textstring;printer:default;width:700px;height:930px;"
End If
 
JavaScript
var sHtml = oTView.SaveToHtm("ver:1", "return;", "mode:graph;");
if(sHtml != "")
  Pm.PrintHtmlPage(sHtml, "sourcetype:textstring;printer:default;width:700px;height:930px;");
Example2:
Creating the graph HTML page for printing. In this case the HTML page supplied with the PROMOTIC system is used as the empty template (source HTML page) The created HTML page is displayed by the browser and ready, for example, for printing.
oTView.SaveToHtm "ver:1","file:trendprint.htm","mode:graph;"
Pm.ShellExecute "open", "#app:trendprint.htm", "", "#app:", 1
Example3:
Displaying HTML page in the window:
oTView.SaveToHtm "ver:1", "file:trendprint.htm", "mode:table;view:dlg;"
Example4:
Creating the graph HTML page for printing. In this case the copy named trendsrc.htm (located in an application folder) of the HTML page supplied with the PROMOTIC system is used as the HTML template. The created HTML page is displayed by the browser and ready, for example, for printing.
oTView.SaveToHtm "file:trendsrc.htm", "file:trendprint.htm", "mode:graph;view:dlg;"
Example5:
Creating the graph HTML page for printing. In this case the HTML page supplied with the PROMOTIC system is used as the HTML template. Keywords title, note1 and note2 from the HTML template are successively replaced by the strings "Factory station", "Ironware district" and "Page created by John Weiss". The created HTML page is displayed by the browser and ready, for example, for printing.
oTView.SaveToHtm "ver:1", "file:trendprint.htm", "mode:graph;view:dlg;text_title:Factory station;text_note1:Ironware district;text_note2:Page created by John Weiss;"
Example6:
Creating the graphic HTML page for printing. In this case the HTML page supplied with the PROMOTIC system is used as the HTML template. The keyword codeinit from the HTML template is replaced by the following string "oTView.TrendArea.Dx=540", that will reconfigurate the dimension of the item while the page is being loaded. The created HTML page is displayed by the browser and ready, for example, for printing.
Dim sParCode
sParCode = "oTView.TrendArea.Dx = 540;"
oTView.SaveToHtm "ver:1","file:trendprint.htm","mode:graph;view:dlg;text_codeinit:$Par:0;",sParCode
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice