by Jose Dolar » Tue Jan 14, 2014 5:35 am
Here I am posting a small function that works for me.
#Define OLECMDID_PRINT 6
#Define OLECMDEXECOPT_PROMPTUSER 1
#Define OLECMDEXECOPT_DONTPROMPTUSER 2
FUNCTION PrintHtml(cHtmlOrUrl,nCopies,lShow)
static oWnd:=nil, oBar, oIe
local i
default lShow:=.f.,nCopies:=1
if oWnd=nil
DEFINE WINDOW oWnd
DEFINE BUTTONBAR oBar OF oWnd
DEFINE BUTTON OF oBar;
PROMPT 'Print';
ACTION oIe:Do( "ExecWB", OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER )
oIe = TActiveX():New( oWnd, "Shell.Explorer" )
endif
oIe:Do( "Navigate2", cHtmlOrUrl)
do while alltrim(oIe:document:readyState) <> 'complete'
sysrefresh()
waitseconds(.5)
enddo
if lshow
oWnd:oClient = oIe
ShowWindow(oWnd, 1 ) && 1=Show,0=hide
ACTIVATE WINDOW oWnd
oWnd:Center()
else
for i=1 to nCopies
msgwait('Printing large receipt (' + alltrim(str(i)) + ' of '+alltrim(str(nCopies))+' copies).',,2)
oIe:Do( "ExecWB", OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER )
next i
endif
sysrefresh()
RETURN nil
There is still room for improvement for this function. If there is a way to send a command to the printer for the number of copies instead of using a loop will make this a lot better.
Thank you for the ideas!
Jose