These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Acrobat not releasing / closing document through OLE with VB.Net

gwaddell
Registered: Jan 8 2010
Posts: 9

Hi,

I'm working on an application that prints batches of documents with OMR in VB.net (OMR - are markings that allow the OMR enabled printer to fold documents etc into envelopes automatically)

As I'm printing these documents in batches for a number of people, I need to work on a document, print it with the OMR marks and then close/release it, move on to another document and then come back to the document when I'm on the next person and so fourth.

However, despite closing the PDDoc and AVDocument the document is still being kept open by Acrobat and an Acrobat process is running in my task manager.

Here is a brief snap shot of my code:

Public Sub PrintAdobeOMR(ByRef sFile As String)
           dim AcroAVDoc, AcroPDDoc as Object
 
             AcroAVDoc = CreateObject("AcroExch.AVDoc")
             AcroAVDoc.open(sFile, Dir(sFile))
             AcroPDDoc = AcroAVDoc.GetPDDoc
             '.... OMRStuff happens here
             AcroAVDoc.PrintPagesSilent(0, AcroPDDoc.GetNumPages- 1, 2, False, False)
            'close up PDDoc
            AcroPDDoc.Close()
            ReleaseActiveX(AcroPDDoc) 'code to try and release COM/ActiveX objects
            AcroPDDoc = nothing
            'close AV Doc
            AcroAVDoc.Close(True)
            ReleaseActiveX(AcroAVDoc)
            AcroAVDoc = Nothing
end sub
 
Public Sub ReleaseActiveX(ByVal o As Object)
        'ensures active X / Com objects are closed
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
        Catch ex As Exception
        Finally
            o = Nothing
        End Try
    End Sub

As I said, the next time the application goes to open the document, I get an error saying the file is already open in Acrobat. I'm probably missing something simple but what....

Thanks
G

My Product Information:
Acrobat Pro 7.0, Windows
gwaddell
Registered: Jan 8 2010
Posts: 9
No one out there any ideas?
gwaddell
Registered: Jan 8 2010
Posts: 9
OK,
I tried using this code too, which at the time I thought was overkill but it still will not close...
Public Sub KillAcrobat()Dim myProcess As ProcessOn Error Resume NextIf Process.GetProcessesByName("Acrobat").Length > 0 Then'acrobat is still openDo Until Process.GetProcessesByName("Acrobat").Length = 0'get each instance of AcrobatFor Each myProcess In Process.GetProcessesByName("Acrobat")'Attempt to close itmyProcess.Close()Threading.Thread.Sleep(1000) 'wait either a secondIf Not myProcess.HasExited Then 'still not gonemyProcess.Kill() ' force closureEnd IfmyProcess = NothingNextLoopEnd IfmyProcess = NothingEnd Sub