Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PDF Viewing - Microsoft Web Browser control closes the form itself - Doesn't seem to work 1

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
549
MU
Hi Team,

I have a form. I have dropped Microsoft Web Browser OLE control.
I have a button on form. On CLICK of button I have following code (took from
Code:
LOCAL lnSeconds
Thisform.cPdfFileName = GETFILE("pdf")
This.nPdfLoadTimeout = 30

* Clear Web browser control by loading blank page
Thisform.oWB.OBJECT.Navigate2("About:Blank")
* Wait for load to complete
lnSeconds = SECONDS()
DO WHILE (Thisform.oWB.OBJECT.Busy OR Thisform.oWB.OBJECT.ReadyState <> 4) ;
	AND (SECONDS() - lnSeconds) < This.nPdfLoadTimeout
	DOEVENTS
ENDDO

* Load PDF
WAIT WINDOW NOWAIT "Loading PDF ..."
Thisform.oWB.OBJECT.Navigate2(Thisform.cPdfFileName)
* Wait for PDF to load
lnSeconds = SECONDS()
DO WHILE (Thisform.oWB.OBJECT.Busy OR Thisform.oWB.OBJECT.ReadyState <> 4) ;
	AND (SECONDS() - lnSeconds) < This.nPdfLoadTimeout
        DOEVENTS
ENDDO
WAIT CLEAR

But when I select a PDF to view, the form itself getting closed.
However, I can view the PDF in Acrobat Reader or if I drop the file in my Chrome browser, it is displayed.

Mine is Windows 10, 64bit

Anyone has any idea ?

Thanks
Rajesh
 
What if you reduce the whole code to:

Thisform.oWB.OBJECT.Navigate2(Thisform.cPdfFileName)

or

Thisform.Olecontrol1.Navigate2(Thisform.cPdfFileName)


In my test the PDF will always return Busy = .T. (nowadays?)
 
Dear Jack,

Oh! My God! That was marvelous!
It was as simple as that! Thank you very much.

I am wondering why I didn't think that way.
In fact, I had done this before but just forgot.
Maybe, that code to wait for it to finish loading etc etc confused me.

However, I think, in case if the PDF is a bit huge, it may take some time to load
and I will have to have a work around for that?

Thank you once again.
Rajesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top