[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Acrobat doesn't give the file-lock back

Asked by zimba-tm in Adobe Acrobat

Tags: sechandler

Hello !

I have implemented the pdf signature in VB.net. Unfortunately, after the process, Adobe still uses the file and I can't move or delete it.
Currently, I'm using the latest Acrobat 7.0 SDK and Acrobat Pro 7.0 Beta 5.

Here is the developped code :
-----------------------------------------------
Public Class SignPdfWithAcrobat
    Const SignError = 1
    'Private m_PDDoc As Acrobat.CAcroPDDoc
    '   Private m_jso As Object
    '   Private m_secHandler As Object
    Private m_sigFilePath As String
    Private m_sigPassword As String

    ' -----------------------------------------------------------------------------------------------------------------
    ' Constructeur
    '
    ' m_sigFilePath   : chemin du fichier pfx de signature. Le mot de passe correspond à celui de cette signature
    ' m_sigPassword   : password de la signature
    ' -----------------------------------------------------------------------------------------------------------------
    Public Sub New(ByVal p_sigFilePath As String, ByVal p_sigPassword As String)

        ' connection a acrobat
        'm_PDDoc = CreateObject("AcroExch.PDDoc")

        m_sigFilePath = p_sigFilePath
        m_sigPassword = p_sigPassword

    End Sub

    ' -----------------------------------------------------------------------------------------------------------------
    ' Methode de signature d'un document PDF
    ' Créée un champ signature
    ' puis y appose la signature et sauvegarde le fichier signé
    '
    ' m_inPDFFilePath : fichier à signer (chemin complet)
    ' -----------------------------------------------------------------------------------------------------------------
    Public Sub Sign(ByVal p_inPDFFilePath As String)
        Dim _PAGE_NUMBER_ = 0
        Dim _LEFT_X_COORD_ = 10
        Dim _BOX_LENGTH_ = 200
        Dim _TOP_Y_COORD_ = 10
        Dim _BOX_HEIGHT_ = 60
        Dim _FIELD_NAME_ = "Signature"
        Dim _FIELD_TEXT_ = "FieldText"

        Sign_Full(p_inPDFFilePath, m_sigPassword, m_sigFilePath, p_inPDFFilePath, _PAGE_NUMBER_, _LEFT_X_COORD_, _BOX_LENGTH_, _TOP_Y_COORD_, _BOX_HEIGHT_, _FIELD_NAME_)
    End Sub

    ' -----------------------------------------------------------------------------------------------------------------
    ' Methode de signature d'un document PDF
    ' Créée un champ signature
    ' puis y appose la signature et sauvegarde le fichier signé. Pour rendre le champ invisible,
    ' utiliser Width et Length à zéro
    '
    ' m_inPDFFilePath : fichier à signé (chemin complet)
    ' m_sigPassword   : password de la signature
    ' m_sigFilePath   : chemin du fichier pfx de signature. Le mot de passe correspond à celui de cette signature
    ' _PAGE_NUMBER_   : page du document à signer
    ' _LEFT_X_COORD_  : coordonnée gauche de la signaure
    ' _BOX_LENGTH_    : taille de la boite de signature
    ' _TOP_Y_COORD_   : hauteur de l'emplacement de la signature
    ' _BOX_HEIGHT_    : largeur de la boite de signature
    ' _FIELD_NAME_    : nom duc hamp de signature
    ' -----------------------------------------------------------------------------------------------------------------
    Public Sub Sign_Full(ByVal p_inPDFFilePath As String, ByVal p_sigPassword As String, ByVal p_sigFilePath As String, _
                    ByVal p_outPDFFilePath As String, ByVal _PAGE_NUMBER_ As Integer, ByVal _LEFT_X_COORD_ As Integer, _
                    ByVal _BOX_LENGTH_ As Integer, ByVal _TOP_Y_COORD_ As Integer, ByVal _BOX_HEIGHT_ As Integer, _
                    ByVal _FIELD_NAME_ As String)
        Dim m_PDDoc As Acrobat.CAcroPDDoc
        Dim gPage As Acrobat.CAcroPDPage
        Dim jso As Object
        Dim pageRect As Object
        Dim formFieldRect(3) As Integer
        Dim formField As Object
        Dim secHandler As Object

        Try

            m_PDDoc = CreateObject("AcroExch.PDDoc")

            ' ouverture du fichier a signer
            If m_PDDoc.Open(p_inPDFFilePath) Then
                jso = m_PDDoc.GetJSObject

                ' *** Load security
                ' validate signatures when the document is opened
                jso.security.validateSignaturesOnOpen = True

                ' *** Create the field
                gPage = m_PDDoc.AcquirePage(_PAGE_NUMBER_)
                pageRect = gPage.GetSize

                ' Taille et position du champ de signature
                formFieldRect(0) = _LEFT_X_COORD_
                formFieldRect(2) = formFieldRect(0) + _BOX_LENGTH_
                formFieldRect(1) = pageRect.Y - _TOP_Y_COORD_ - _BOX_HEIGHT_
                formFieldRect(3) = formFieldRect(1) + _BOX_HEIGHT_

                ' AJout du champ dans le document
                formField = jso.AddField(_FIELD_NAME_, "signature", _PAGE_NUMBER_, formFieldRect)

                ' *** Configure field's style
                'formField.BorderStyle = jso.border.s
                'formField.TextSize = 0
                'formField.LineWidth = 3
                'formField.TextColor = jso.Color.black
                'formField.StrokeColor = jso.Color.black
                'formField.FillColor = jso.Color.transparent
                'formField.textFont = jso.Font.HelvB
                'formField.ReadOnly = True
                ' FM le 31/05/2005 : on rend le champ de signature est invisible
                ' JP le 06/06/2005 : utiliser width et height à zéro pour obtenir le même comportement
                ''formField.Display = jso.Display.Visible
                ''formField.Display = jso.Display.noPrint ' Pour avoir une signature visible mais non imprimable
                formField.Display = jso.Display.Hidden

                ' *** Add signature
                secHandler = jso.security.getHandler("Adobe.PPKLite", True)
                If secHandler.login(p_sigPassword, p_sigFilePath) Then
                    ' Signe le champ
                    If Not formField.signatureSign(secHandler) Then
                        Err.Raise(vbObjectError + 512 + SignError, "SignPdfWithAcrobat.Sign_Full", "Cannot sign field")
                    End If

                    ' Teste si la signature est valide
                    Dim status = formField.signatureValidate()
                    If status < 3 Then
                        Err.Raise(vbObjectError + 512 + SignError, "SignPdfWithAcrobat.Sign_Full", "Invalid signature :" & formField.signatureInfo().statusText())
                    End If

                    ' *** Save the file
                    m_PDDoc.Save(&H1, p_outPDFFilePath)
                    secHandler.logout()
                Else
                    Err.Raise(vbObjectError + 512 + SignError, "SignPdfWithAcrobat.Sign_Full", "Cannot get security handler :" & Err.Description)
                End If
            End If
        Catch ex As Exception
            Err.Raise(vbObjectError + 512 + SignError, "SignPdfWithAcrobat.Sign_Full", "Sign Exception raise : " & Err.Description)
        Finally
            'fermeture du fichier
            m_PDDoc.Close()

            System.Runtime.InteropServices.Marshal.ReleaseComObject(gPage)
            System.Runtime.InteropServices.Marshal.ReleaseComObject(m_PDDoc)

            m_PDDoc = Nothing
            gPage = Nothing
            jso = Nothing
            pageRect = Nothing
            formField = Nothing
            secHandler = Nothing

        End Try

    End Sub

    ' -----------------------------------------------------------------------------------------------------------------
    ' Teste si le fichier de signature est valide (accessibilité et mot de passe du fichier)
    '
    ' m_sigFilePath   : chemin du fichier pfx de signature. Le mot de passe correspond à celui de cette signature
    ' m_sigPassword   : password de la signature
    ' return          : false = erreur
    ' -----------------------------------------------------------------------------------------------------------------
    Public Function TestSignature(ByVal m_sigPassword As String, ByVal m_sigFilePath As String) As Boolean
        Dim gPDDoc As Acrobat.CAcroPDDoc
        Dim jso As Object
        Dim secHandler As Object

        gPDDoc = CreateObject("AcroExch.PDDoc")
        jso = gPDDoc.GetJSObject

        secHandler = jso.security.getHandler("Adobe.PPKLite", True)

        Return secHandler.login(m_sigPassword, m_sigFilePath)
    End Function

End Class
[+][-]06/09/05 06:56 AM, ID: 14179737Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Adobe Acrobat
Tags: sechandler
Sign Up Now!
Solution Provided By: khkremer
Participating Experts: 1
Solution Grade: C
 
[+][-]06/09/05 06:57 AM, ID: 14179758Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/09/05 07:09 AM, ID: 14179903Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81