How to release PDF immediately?

New Here ,
Jan 21, 2019

Copy link to clipboard

Copied

I will extract the note in PDF file.

When calling Acrobat API from VB.NET, the file will remain open and locked. Also, if I check the task manager, the Acrobat process may not finish, there may be a considerable time lag by the end.

In the code, it seems that PDF has been opened in Acrobat even though processing to close PDF is included.

It is OK even if Acrobat is left in the process, but I want to realize the process of closing the file immediately and releasing the lock as soon as the use of the file is over. What kind of code should be assembled to start Acrobat hidden in VB.NET and close the file opened with AcroPDDoc?

sample code :

    Private Function GetNoteOnPDF(ByVal filepath As String) As String

        GetNoteOnPDF = ""

        Dim objAcroApp As New Acrobat.AcroApp

        Dim objAcroPDDoc As New Acrobat.AcroPDDoc

        Dim objAcroPDPage As Acrobat.AcroPDPage

        Dim objAcroPDAnnot As Acrobat.AcroPDAnnot

        Dim lRet As Boolean

        Dim note As String = ""

        Try

            lRet = objAcroApp.Hide()

            If lRet = False Then

                Exit Function

            End If

            lRet = objAcroPDDoc.Open(filepath)

            If lRet = False Then

                Exit Function

            End If

            For i As Integer = 0 To objAcroPDDoc.GetNumPages - 1

                objAcroPDPage = CType(objAcroPDDoc.AcquirePage(i), Acrobat.AcroPDPage)

                For j As Integer = 0 To objAcroPDPage.GetNumAnnots() - 1

                    objAcroPDAnnot = CType(objAcroPDPage.GetAnnot(j), Acrobat.AcroPDAnnot)

                    With objAcroPDAnnot

                        Select Case .GetSubtype

                            Case "Text"

                                note += .GetContents

                        End Select

                    End With

                Next j

            Next

            Return note

        Catch ex As Exception

            MessageBox.Show("error :" & ex.Message)

        Finally

            objAcroPDDoc.Close()

            objAcroApp.CloseAllDocs()

            lRet = objAcroApp.Exit

            objAcroPDAnnot = Nothing

            objAcroPDPage = Nothing

            objAcroPDDoc = Nothing

            objAcroApp = Nothing

        End Try

    End Function

TOPICS
Acrobat SDK and JavaScript

Views

184

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How to release PDF immediately?

New Here ,
Jan 21, 2019

Copy link to clipboard

Copied

I will extract the note in PDF file.

When calling Acrobat API from VB.NET, the file will remain open and locked. Also, if I check the task manager, the Acrobat process may not finish, there may be a considerable time lag by the end.

In the code, it seems that PDF has been opened in Acrobat even though processing to close PDF is included.

It is OK even if Acrobat is left in the process, but I want to realize the process of closing the file immediately and releasing the lock as soon as the use of the file is over. What kind of code should be assembled to start Acrobat hidden in VB.NET and close the file opened with AcroPDDoc?

sample code :

    Private Function GetNoteOnPDF(ByVal filepath As String) As String

        GetNoteOnPDF = ""

        Dim objAcroApp As New Acrobat.AcroApp

        Dim objAcroPDDoc As New Acrobat.AcroPDDoc

        Dim objAcroPDPage As Acrobat.AcroPDPage

        Dim objAcroPDAnnot As Acrobat.AcroPDAnnot

        Dim lRet As Boolean

        Dim note As String = ""

        Try

            lRet = objAcroApp.Hide()

            If lRet = False Then

                Exit Function

            End If

            lRet = objAcroPDDoc.Open(filepath)

            If lRet = False Then

                Exit Function

            End If

            For i As Integer = 0 To objAcroPDDoc.GetNumPages - 1

                objAcroPDPage = CType(objAcroPDDoc.AcquirePage(i), Acrobat.AcroPDPage)

                For j As Integer = 0 To objAcroPDPage.GetNumAnnots() - 1

                    objAcroPDAnnot = CType(objAcroPDPage.GetAnnot(j), Acrobat.AcroPDAnnot)

                    With objAcroPDAnnot

                        Select Case .GetSubtype

                            Case "Text"

                                note += .GetContents

                        End Select

                    End With

                Next j

            Next

            Return note

        Catch ex As Exception

            MessageBox.Show("error :" & ex.Message)

        Finally

            objAcroPDDoc.Close()

            objAcroApp.CloseAllDocs()

            lRet = objAcroApp.Exit

            objAcroPDAnnot = Nothing

            objAcroPDPage = Nothing

            objAcroPDDoc = Nothing

            objAcroApp = Nothing

        End Try

    End Function

TOPICS
Acrobat SDK and JavaScript

Views

185

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 21, 2019 0

Have something to add?

Join the conversation