Skip to main content
Participating Frequently
February 21, 2008
Question

Add Digital Signature Using C# and Acrobat SDK

  • February 21, 2008
  • 56 replies
  • 47978 views
Hi everybody!

Please, how can I digitally sign PDF documents using Acrobat Professional 8 API and C# language?
I know that I need use JavaScript APIs (IAC) but I can't find anything really helpful in the Acrobat SDK Documentation. Could anyone post a sample of how use javascript manipulation inside C# (Framework 2.0), or give me a direction?

Thank in advance!
This topic has been closed for replies.

56 replies

Patrick_Leckey
Participating Frequently
March 4, 2008
Which methods are you using to try and sign the document?
Participating Frequently
March 4, 2008
Hi Felipe

Even i am encountering same problem. There is no error or exception while executing the code but pdf is not getting signed.

PDL -- can you please post the code that you have written in C#.
Patrick_Leckey
Participating Frequently
March 3, 2008
It most certainly is possible to call JS from C#.

Once you have your JSObject:

jso.AddSignature();

If you are not able to call any functions via the JSObject then you have not declared or assigned it properly.
Participant
September 4, 2009

In regards to the post by Patrick I must be missing something and was wondering if someone could help me out:

"It most certainly is possible to call JS from C#.
Once you have your JSObject:
jso.AddSignature();
If you are not able to call any functions via the JSObject then you have not declared or assigned it properly"

I have a C# app with a reference to Interop.Acrobat.dll and I am trying to add a bookmark to the PDF. Since this dll is COM I am assuming that it is wrapped with RCW(Runtime Callable Wrapper)? I grabbed the dll from the SDK example project BasicIacJsoVB. I am able to view the properties and methods for strongly typed objects such as AcroApp and CAcroAVDoc. However, for the object returned from GetJSObject() intellisense just shows the methods for the object base class(ToString, Equals, GetHashCode, GetType). I don't see any other methods and the project won't build with the code below. I would prefer not to use late binding as the examples shown in previous posts. Any ideas?

----------------------------------------------------------------------------------------------------------------------------------

            string gPDFPath;

            object jso;
            object BMR;
            object BMC;

            //hard coding for a PDF to open, it can be changed when needed.
            gPDFPath = @"C:\test1\1.pdf";

            Acrobat.AcroApp gApp = new Acrobat.AcroAppClass();

            // show Acrobat
            gApp.Show();

            //Set AVDoc object
            Acrobat.CAcroAVDoc gAvDoc =  new Acrobat.AcroAVDocClass();

            // open the PDF
            if (gAvDoc.Open(gPDFPath, ""))
            {
              
                Acrobat.CAcroPDDoc gPdDoc = gAvDoc.GetPDDoc() as Acrobat.CAcroPDDoc;
                jso = gPdDoc.GetJSObject();
                BMR = jso.BookmarkRoot();
                //BMR.createchild("First Topic", "this.pageNum= 0", 0);
            }

-------------------------------------------------------------------------------------------------------------------------------------

Participating Frequently
March 3, 2008
Hi Sumit,

I could not use C#, I am using here VB.NET, because I could not call a javascript method from c#, I think that is not possible. So, I put the sdkAddSignature.js file into the Acrobat Javascript folder and I used the VB.NET sample that exists inside this file, like below:

Dim AVDoc As Acrobat.AcroAVDoc
AVDoc = CreateObject("AcroExch.AVDoc")
AVDoc.Open("c:\\myfile.pdf", "Any Title")

' get acrobat form object
Dim formApp As AFORMAUTLib.AFormApp
formApp = CreateObject("AFormAut.App")

' access some object property in objects inside AcroForm.
Dim fields As AFORMAUTLib.Fields

fields = formApp.Fields()

'Sign the document
Dim menuItem As String
Dim digitalIDPwd As String
Dim digitalIDPath As String

digitalIDPwd = "testpassword"
digitalIDPath = "c:\\DrTest.pfx"
menuItem = "ADBESDK:AddSignature"

Dim jsCode As String
'Dim jsRc As Boolean
jsCode = "SetUserPassword(" + "'" + digitalIDPwd + "'); SetUserDigitalIDPath(" + "'" + digitalIDPath + "');" + "app.execMenuItem('" + menuItem + "');"
' Execute JS code to sign doc
fields.ExecuteThisJavascript(jsCode)

'save & close
AVDoc.Close(True)

The code above works without errors, but doesn't apply a digital signature in the document.

The code above, execute the Javascript command below in the Acrobat:

SetUserPassword('testpassword');
SetUserDigitalIDPath('c:\\DrTest.pfx');
app.execMenuItem('ADBESDK:AddSignature');

If I execute the commands directly from Javascript Debugger inside the Adobe Acrobat Professional 8, the document is signed, but using the VB.net code, there is no error, but there is no signature too.
Participating Frequently
March 3, 2008
Hi PDL,

I am using following code to add signature in pdf

Acrobat.AcroAVDoc acroAVDoc = new Acrobat.AcroAVDoc();
acroAVDoc.Open(@"c:\test.pdf", "TempTitle");

Acrobat.CAcroPDDoc acroDoc = (Acrobat.CAcroPDDoc)acroAVDoc.GetPDDoc();
acroDoc.Open(@"c:\test.pdf");

Object jso = acroDoc.GetJSObject();

but i didn't find how to call javascript?

can you please tell me how can i call the method of AddSignature in sdkAddSignature.js?

Sumit
Participating Frequently
February 28, 2008
Well, I can't use the JSObject with C#, only in VB.NET.
I will do what I need with VB.NET, is not so bad.

Thank you very much!!!
I thank the patient for all!
Patrick_Leckey
Participating Frequently
February 27, 2008
In many varied projects I have successfully used the IAC JSObject in VBScript, VB.NET and C#.
Participating Frequently
February 27, 2008
Hi PDL!!

It works here, but in VB.NET.
You really did it in C#?
Patrick_Leckey
Participating Frequently
February 27, 2008
You only need to open the document once, then you can just get the PDDoc from the AVDoc.

To call my document-level function named showMyMessage() which was declared as follows (document-level javascript):

function showMyMessage()
{
console.show();
console.clear();
console.println("Success.");
}

I then called it like this:

jso.showMyMessage();
Participating Frequently
February 27, 2008
Hi again PDL, your last message was very useful, thank you a lot.
Below are my code, I think that I am almost close to the solution:

AcroAVDoc acroAVDoc = new AcroAVDoc();
acroAVDoc.Open(@"c:\f.pdf", "TempTitle");

CAcroPDDoc acroDoc = (CAcroPDDoc)acroAVDoc.GetPDDoc();
acroDoc.Open(@"c:\f.pdf");

Object jso = acroDoc.GetJSObject();

I am trying to open the file "f.pdf" and trying to execute the javascript methods. When I execute the code, there is no errors, and the "f.pdf" file opens in a Acrobat 8 window. But now, I don't know what should I do to execute the javascript.

Do you have any orientation?
Or could you post the code of the test that you did in the other message(MESSAGE: 6:12am Feb 26, 08 PST (#15))

Thank you!