FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to print HTML file?
Posts: 52
Joined: Thu Mar 22, 2012 05:43 PM
How to print HTML file?
Posted: Sun Jan 12, 2014 05: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

Posts: 838
Joined: Fri Feb 10, 2006 12:14 PM
Re: How to print HTML file?
Posted: Sun Jan 12, 2014 01:43 PM

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

Antonio Ferreira

Regards

Antonio H Ferreira
Posts: 52
Joined: Thu Mar 22, 2012 05:43 PM
Re: How to print HTML file?
Posted: Sun Jan 12, 2014 06: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

Posts: 838
Joined: Fri Feb 10, 2006 12:14 PM
Re: How to print HTML file?
Posted: Mon Jan 13, 2014 09: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
Posts: 52
Joined: Thu Mar 22, 2012 05:43 PM
Re: How to print HTML file?
Posted: Tue Jan 14, 2014 05: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

Continue the discussion