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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PDF viewer form crashing on close using pdf.ocx

Status
Not open for further replies.

svankley

MIS
Aug 25, 2000
45
US
I have a VB app that needs to open a pdf document and go to a particular page in it. I'm using the Adobe Acrobat Control for ActiveX (pdf.ocx). The control is called 'pdfmain'.

I have the following code on the form:

Dim Status As Integer

Status = pdfmain.LoadFile(PDF_Filename)
If Status <> -1 Then GoTo errHandler
'PDF_Page = InputBox("What Page?")
pdfmain.setCurrentPage (Project_User.PDF_Page)
pdfmain.Width = Me.Width
pdfmain.Height = Me.Height


When the form opens, you see the Adobe splash screen as the control is loaded. The form opens after the Adobe Splash screen and goes to the exact page it's supposed to. The problem is that when this form is closed, 80% of the time abobe crashes.
But, if I start Adobe Acrobat and minimize it just to have it open, everything works PERFECTLY!
Is there a way to code this differently so it won't crash, or is there a way to load acrobat into memory so it doesn't take too long to load and so the form then closes properly?

Thanks for any assistance!

Steve
 
Steve,

can you open Acrobat in the first with code...

something like shell 'acrobat'
It seems that the ocx is leaving a hook in the acrobat process, and when the variable is going out of scope (when the form that started it is closed) that it tries to close acrobat also (just not well)

I have played with the vbscript run (or is it the exe method) command also.. it does a nice job of opening apps. Provides sync and async exection modles.

I think shell also lets you open things minimised, but my approach would be to try to open it minimised (sync mode) and on completion use the active x control to load your doc...

Hope it works (let me know:)

Rob
PS no humididy here today (I got to go surfing yesterday.. 6 foot lake michigan :)

 
Yes, I guess I could make sure Acrobat is open in the beginning and if it's not, then open it with shell. The only reason I'm not using shell to do everything is because I need to make the PDF open to a user defined page.

Is it possible to start the app (acrobat.exe), or any app just in memory without the GUI. This way I don't have to worry about the user seeing/finding the app and shutting it down. Just a side-thought.

Thanks!!

p.s. You should have some killer surf with all the weather that's been goin' through the area.
Low Humidity? Want some of ours - We have more than our share today!!
 
You can use the ShellExecute API to run Acrobat, and you can pass it a user-defined file. Put the following in the General/Declarations section of your form:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_HIDE = 0
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWDEFAULT As Long = 10
Private Const SE_ERR_NOASSOC As Long = 31

Then, just call the function like so:

Dim PDFName As String

PDFName = "C:\Path\to\your\pdf\filename.pdf"

ShellExecute Me.hwnd, vbNullString, PDFName, vbNullString, vbNullString, SW_SHOWMAXIMIZED

This will open Acrobat (or whatever program you have associated with the .pdf extension in Windows) with the file specified, and maximize the window.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top