basquang™ on clouds

November 5, 2010

Add Digital Signature to a PDF programmatically using Adobe SDK and Microsoft .NET

Filed under: Digital Signature,PDF — basquang @ 11:18 AM

Requirement:

– Adobe Professional Installed

– Adobe SDK downloaded

– Microsoft Visual Studio

– Valid Certificate file (.pfx). It means the .pfx file not yet expired.

Setup environment:

– Copy sdkAddSignature.js from SDK to Acrobat\Javascripts folder

– Optional: Create Your Own Test Certificate

Code C#

Type AcrobatCAcroAppType;
            AcrobatCAcroAppType = Type.GetTypeFromProgID("AcroExch.app");
            Acrobat.CAcroApp gapp = (Acrobat.CAcroApp)Activator.CreateInstance(AcrobatCAcroAppType);

            Type AcrobatPDDocType;
            AcrobatPDDocType = Type.GetTypeFromProgID("AcroExch.PDDoc");
            Acrobat.CAcroPDDoc gpddoc = (Acrobat.CAcroPDDoc)Activator.CreateInstance(AcrobatPDDocType);

            object jso;

            if (gpddoc.Open("d:\\temp\\s.pdf"))
            {
                jso = gpddoc.GetJSObject();
                object[] param = new object[1];

                param[0] = "c:\\CATest.pfx";

                object con = jso.GetType().InvokeMember("SetUserDigitalIDPath",
                BindingFlags.InvokeMethod, null, jso, param);

                param[0] = "testpassword";
                con = jso.GetType().InvokeMember("SetUserPassword",
                BindingFlags.InvokeMethod, null, jso, param);                    
                param[0] = jso;

                con = jso.GetType().InvokeMember("AddSignature",
                BindingFlags.InvokeMethod, null, jso, param);            
            }

Code VB:

Dim gapp As Acrobat.CAcroApp
    Dim gpddoc As Acrobat.CAcroPDDoc
    Dim jso As Object
    gapp = CreateObject("acroexch.app")
    gpddoc = CreateObject("acroexch.pddoc")

    If gpddoc.Open("d:\temp\s.pdf") Then
      jso = gpddoc.GetJSObject()
      jso.SetUserPassword("testpassword")
      jso.SetUserDigitalIDPath("/C/CATest.pfx")
      jso.AddSignature(jso)
      gapp.Show()
    End If

basquang@hotmail.com

Advertisements

3 Comments »

  1. Excellent post. I was checking constantly this weblog and I am impressed!
    Extremely helpful information specifically the last section 🙂 I take care of such info a lot.
    I used to be looking for this particular information for a very long time.
    Thank you and good luck.

    Comment by Women Fashion — February 20, 2015 @ 3:52 AM | Reply

  2. Nice blog post , my friend last month happened across https://goo.gl/Ncrgef to modify pdf ! It’s notably straightforward to try out and it’s good – I saw on the website they have a free trial now

    Comment by Jeremy Garfield — September 22, 2016 @ 1:54 PM | Reply

  3. I cannot find sdkAddSignature.js file. and thus getting error at
    object con = jso.GetType().InvokeMember(“SetUserDigitalIDPath”,
    BindingFlags.InvokeMethod, null, jso, param);
    Could you please help in this.

    Comment by Sumit — October 2, 2016 @ 5:56 PM | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: