How to print HTML file?

How to print HTML file?

Postby Jose Dolar » Sun Jan 12, 2014 5:39 am

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
Jose Dolar
 
Posts: 52
Joined: Thu Mar 22, 2012 5:43 pm
Location: USA

Re: How to print HTML file?

Postby AHF » Sun Jan 12, 2014 1:43 pm

Try ShellExecute(hWnd,"PrintTo",htmlfile,,0,1)


Antonio Ferreira
Regards
Antonio H Ferreira
AHF
 
Posts: 838
Joined: Fri Feb 10, 2006 12:14 pm

Re: How to print HTML file?

Postby Jose Dolar » Sun Jan 12, 2014 6:58 pm

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
Jose Dolar
 
Posts: 52
Joined: Thu Mar 22, 2012 5:43 pm
Location: USA

Re: How to print HTML file?

Postby AHF » Mon Jan 13, 2014 9:08 am

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
Regards
Antonio H Ferreira
AHF
 
Posts: 838
Joined: Fri Feb 10, 2006 12:14 pm

Re: How to print HTML file?

Postby 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
Jose Dolar
 
Posts: 52
Joined: Thu Mar 22, 2012 5:43 pm
Location: USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Otto and 72 guests