BTW: You are no longer allowed to use the beta5 version after Acrobat 7 was released. I think Adobe gives you a grade period of one month after the release.
Main Topics
Browse All TopicsHello !
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.PDD
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,
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.PDD
' ouverture du fichier a signer
If m_PDDoc.Open(p_inPDFFilePa
jso = m_PDDoc.GetJSObject
' *** Load security
' validate signatures when the document is opened
jso.security.validateSigna
' *** Create the field
gPage = m_PDDoc.AcquirePage(_PAGE_
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_,
' *** 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("A
If secHandler.login(p_sigPass
' Signe le champ
If Not formField.signatureSign(se
Err.Raise(vbObjectError + 512 + SignError, "SignPdfWithAcrobat.Sign_F
End If
' Teste si la signature est valide
Dim status = formField.signatureValidat
If status < 3 Then
Err.Raise(vbObjectError + 512 + SignError, "SignPdfWithAcrobat.Sign_F
End If
' *** Save the file
m_PDDoc.Save(&H1, p_outPDFFilePath)
secHandler.logout()
Else
Err.Raise(vbObjectError + 512 + SignError, "SignPdfWithAcrobat.Sign_F
End If
End If
Catch ex As Exception
Err.Raise(vbObjectError + 512 + SignError, "SignPdfWithAcrobat.Sign_F
Finally
'fermeture du fichier
m_PDDoc.Close()
System.Runtime.InteropServ
System.Runtime.InteropServ
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.PDD
jso = gPDDoc.GetJSObject
secHandler = jso.security.getHandler("A
Return secHandler.login(m_sigPass
End Function
End Class
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Well,
I solved my problem myself.
It was exactly like you said, with two exceptions :
- m_PDDoc.Close() doesn't release the file, you have to get the AVDoc like in : m_PDDoc.getAVDoc().close(T
- Same for gPage. Because I didn't want to show the field anyway, I used the 0,0,0,0 coords.
Thanks for your effort, you've got the points !
Cheers,
... zimba
Business Accounts
Answer for Membership
by: khkremerPosted on 2005-06-09 at 06:56:07ID: 14179737
You have to set the m_PDDoc variable to NULL once you are done, this will free the object. Do this for all the objects you no longer need (e.g. pages, form fields, ...)