Micro Focus QTP (UFT) Forums
Closing an open PDF - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Closing an open PDF (/Thread-Closing-an-open-PDF)



Closing an open PDF - mv8167 - 08-15-2012

What ise wrong with: **

Code:
Set AcroAVDoc = CreateObject( "AcroExch.AVDoc" )

' Open the PDF
If AcroAVDoc.Open( gPDFPath, "" ) Then
        If AcroAVDoc.IsValid = False Then ExitTest()
        AcroAVDoc.BringToFront()
        Call AcroAVDoc.Maximize( True )
        Set AcroPDDoc = AcroAVDoc.GetPDDoc()
        PDFName = AcroPDDoc.GetFileName()
        PDFPageCount = AcroPDDoc.GetNumPages()
End If

'** NONE OF THE BELOW CLOSE THE PDF

Code:
AVDoc.CloseAllDocs()  
AVDoc.Exit()          
                      
AcroAVDoc.CloseAllDocs(
AcroAVDoc.Exit()      
                        
AcroExch.CloseAllDocs()
AcroExch.Exit()  
      
Set AcroApp = Nothing
Set AcroAVDoc = Nothing


WHAT AM I DOING WRONG? (I think I made a mess of this)


RE: Closing an open PDF - ravi.gajul - 08-19-2012

Hi,
Please see the corrected code below
Code:
Set AcroApp = CreateObject( "AcroExch.App" )
Set AcroAVDoc = CreateObject( "AcroExch.AVDoc" )
gPDFPath="C:\test.pdf" 'please change the path before execution
' Open the PDF
AcroApp.Show()
AcroApp.Maximize(vbMaximize)
If AcroAVDoc.Open(gPDFPath,"") Then
If AcroAVDoc.IsValid = False Then ExitTest()
AcroAVDoc.BringToFront()
Call AcroAVDoc.Maximize( True )
Set AcroPDDoc = AcroAVDoc.GetPDDoc()
PDFName = AcroPDDoc.GetFileName()
PDFPageCount = AcroPDDoc.GetNumPages()
'msgbox PDFName
'msgbox PDFPageCount
AcroApp.CloseAllDocs()
AcroApp.Exit()
End If
Set AcroApp = Nothing
Set AcroAvDoc = Nothing

Regards,
Ravi


RE: Closing an open PDF - mv8167 - 08-21-2012

Tax again Ravi


but how do i then close my file? What i am trying wont close my open PDF.

thx


RE: Closing an open PDF - ravi.gajul - 08-21-2012

The lines below should close the file
Code:
AcroApp.Hide()
AcroApp.CloseAllDocs()
AcroApp.Exit()
or for cross verification you may check the returnvalue
Code:
AcroApp.Hide()
returnValue1 = AcroApp.CloseAllDocs()  'returnValue= -1 if successful,0 if not
returnValue2 = AcroApp.Exit()
msgbox returnValue1
msgbox returnValue2
Note: AcroApp.Exit() Returns -1(or true) if the entire shutdown process succeeded. This includes closing any open
documents, releasing OLE references, and finally exiting the application. If any step fails,
the function returns 0, and the application will continue running. This method will not
work if the application is visible (if the user is in control of the application). In such
cases, if the Show() method had previously been called, you may call Hide() and then
Exit().
Please let me know your findings.If this doesn't help..please let me know whether or not there is an error message, if so, what it is?

Regards,
Ravi


RE: Closing an open PDF - mv8167 - 08-23-2012

Ravi...

Thx this worked perfectly. I had no error message, i just could not get my PDF to close. I think my earlier code was incorrect.

Your the best, THX


RE: Closing an open PDF - ravi.gajul - 08-23-2012

Glad it worked.Thank you.