Printing html files under Windows with optcl

Kroc - 28/10/2010

This is a quick and dirty trick to print html under Windows without any prompt dialog. It requires optcl and was widely inspired by RS's COM on! - a tiny web browser.

 # load optcl (must be after Tk)
 package require Tk
 package require optcl
 
 # Proc to call to print a file
 proc printhtm {f} {
         if {![file exists $f]} {return 0}
         if {![info exists ::htm]} {
                 catch {::optcl::new -window .htm Shell.Explorer.2} ::htm
         }
         if {![catch {$::htm Navigate [file nativename [file normalize $f]]}]} {
                 update
                 after 2500
                 if {![catch {$::htm ExecWB "OLECMDID_PRINT" "OLECMDEXECOPT_DONTPROMPTUSER"}]} {
                         return 1
                 }
         }
         return 0
 }