Applies To:
  • CitectSCADA 5.xx
  • CitectHMI 5.xx

I am trying to automatically print an HTML report based on a triggered event, but a print dialogue box displays expecting me to select a printer first, which halts the code until the user interacts with the prompt. Is there a way to bypass the print dialogue box? 

There are at least 2 ways to automatically print an HTML report. The first way can be found in Citect's HELP.HTM file found in the Example project (C:\Citect\User\Example). The following instructions are taken from this file:

How to Automatically Print an HTML Report:

1. Write a Citect event to update the trend image before printing the report.

2. Use WinNewAt to create a temporary page to display "File_Htm" where Web Browser ActiveX is embedded.

3. Use HtmFileOpen(STRING AN, STRING FileName) to open the generated report (it actually calls the ActiveX Navigate method). The first argument is the animation point where the ActiveX is created, and the second one is the generated report name including its location.

4. Use HtmFilePrint(STRING AN, INT PrintPrompt) to print the generated report where the second argument is the print option. In this case, use PrintPrompt = 2 to send the report to the default printer.

5. Use WinFree to free the page.

6. Use a Citect event to control steps 2 - 5.

The second way is simpler, and can be used without interfacing with the Web Browser ActiveX control. The following Cicode function can be called from an event or other automated background tasks:

// Print an HTML file to the default printer
// Arguments: sFile Path and filename of the HTML file
// bDisplayDialog FALSE Don't display confirmation dialog (default)
// TRUE Display confirmation dialog
// Example: PrintHTML("C:\Reports\ShiftReport.htm")

FUNCTION PrintHTML(STRING sFile, INT bDisplayDialog = FALSE)

    INT iWinNo;

    iWinNo = WinGetFocus();

    Exec("RunDLL32.exe D:\WINNT\System32\MSHTML.dll,PrintHTML ^"" + sFile + "^"");

    IF bDisplayDialog = FALSE THEN
        WHILE WndFind("Print") = 0 DO // Wait for print dialog to appear
        SendKeys("Print", "{enter}"); // Close the dialog

NOTE: Any URL address can also be printed. For example: