Page 1 of 1

How to print HTML file?

Posted: Sun Jan 12, 2014 5:39 am
by Jose Dolar
Hello Fivewin users /Antonio,

I want to inquire, Is there a way to print HTML file from Harbour + Fivewin application directly to default printer?

We want to streamline our system that is relying on a third party program to print HTML file.

We may also consider upgrading to the latest Harbour and Fivewin Lib if necessary.

Any suggestions will be highly appreciated.

Thank you very much,

Jose

Harbour Compiler: Harbour version 2.1.0
Fivewin Lib: FWH 11.06

Re: How to print HTML file?

Posted: Sun Jan 12, 2014 1:43 pm
by AHF
Try ShellExecute(hWnd,"PrintTo",htmlfile,,0,1)


Antonio Ferreira

Re: How to print HTML file?

Posted: Sun Jan 12, 2014 6:58 pm
by Jose Dolar
Antonio, thank you for the suggestions. I appreciate it.

I tried ShellExecute but it prints one copy only. It does also shows the printer dialog box. We need to print many copies without interruption.

ShellExecute may be a possible solution but we need to hide the printer dialog box and specify the number of copies to print.

Any ideas / suggestions?

Thank you,

Jose

Re: How to print HTML file?

Posted: Mon Jan 13, 2014 9:08 am
by AHF
Jose

Then I think you should try

IE := CreateObject("InternetExplorer.Application")

but I dont know the API may be:

IE:print()

With shellexecute you can set printer with PRN... functions and then SENDMESSAG... function to the printer dlg to press Print button. I never tried it but should work.

I dont have any other alternatives.


Antonio

Re: How to print HTML file?

Posted: Tue Jan 14, 2014 5:35 am
by Jose Dolar
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