Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Add Digital Signature Using C# and Acrobat SDK

New Here ,
Feb 21, 2008 Feb 21, 2008
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!
TOPICS
Acrobat SDK and JavaScript
48.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2008 Feb 25, 2008
Nobody can help?
I can't understand/use javascript manipulation inside my C# app. I created the JSObject (Object jso = acroDoc.GetJSObject()) in my program, but I can't understand how can I invoke javascript codes from the c#. If somebody could post a sample, I would invoke the javascript code, that came with the SDK, to add digital signature.
Just a example to how invoke javascript from the C# would be great helpful!

Thanks!!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 25, 2008 Feb 25, 2008
Have you read the SDK? Have you looked at all the samples that show how to use the JSObject from C#?

What are you still missing?

Leonard
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 25, 2008 Feb 25, 2008
Once you have your javascript object, you can execute any of the functions listed in the JavaScript API documentation by calling:

jso.<method name>(<parameters>);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2008 Feb 25, 2008
Thanks for the help!

Leonard, I read the documentation, but there is no documentation for C# and no sample using JSObject with C#. There are only some samples using some methods of the Acrobat.dll, but nothing really helpful.

PDL, I tried this, but not worked. I think that this just works for VB, right?

Any idea?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 25, 2008 Feb 25, 2008
Look at the VB samples - they work the same way.

Leonard
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 25, 2008 Feb 25, 2008
If that didn't work then you are not acquiring the JSObject correctly. The above method works in C#.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2008 Feb 25, 2008
Maybe, the correct way is this:

jso.GetType().InvokeMember(<method name>(<parameters>))

What do you think?

And other doubt, I know that there is a folder, in the Acrobat Professional directory, where I should put my javascript code, to invoke through my C# application, right?
I searched in the directory, but I didn't find where is the javascript folder. Please, could you tell the javascript folder name?

The "<method name>" would be the name of the javascript code, that is inside the javascript folder?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 25, 2008 Feb 25, 2008
No need for JavaScript to go anywhere other than your C# application.

Leonard
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2008 Feb 25, 2008
I'm sorry Leonard Rosenthol, I'm new with de Acrobat SDK. I think I understand wrong the IAC concept, I thought that I would invoke a javascript code from anywhere. So, I need to make the javascript code directly in my C# application, using the JSO, is it?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 25, 2008 Feb 25, 2008
It's not that you need to write JavaScript code (although you could if you wanted to) - it's that you can/should invoke the JS methods AS IF THEY WERE native C# methods via the JSObject.

Leonard
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 25, 2008 Feb 25, 2008
Ah - you are trying to execute javascript functions you wrote yourself and not the ones exported by the JSObject?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2008 Feb 25, 2008
Yeah PDL, you got the point.
I need to apply a digital signature in a PDF file. I need to do this inside my C# application, because the user will have other features besides signing.
I fond in the SDK documentation a sample of javascript code that digitally sign the document, and I read that I need to invoke a javascript code to digitally sign a pdf with C#, because there are no methods to sign just using the Acrobat.dll. I read that to invoke the javascript code I need to create a JSObject, am I right?

I just need to invoke a javascript code from C#, could you help me? Do you know how can I get this? Could you give a example??

Thank you all very much!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 26, 2008 Feb 26, 2008
Hello!
You wrote on Mon, 25 Feb 2008 09:29:13 -0800:

FF> I just need to invoke a javascript code from C#, could you help me? Do
FF> you know how can I get this? Could you give a example??

Did you consider third-party components for signing PDF directly from C#?
There are several options available and they don't require Adobe SDK.

With best regards,
Eugene Mayevski
http://www.SecureBlackbox.com - the comprehensive component suite for
network security
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 26, 2008 Feb 26, 2008
Yes Eugene. I did exactly what I needed using a component called iTextSharp, but here, in the company, they really want to use the Acrobat SDK, and I know that is possible to invoke a javascript code from C#.

Could anyone help me to invoke a javascript code in C#, using the Acrobat SDK?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 26, 2008 Feb 26, 2008
Felipe -

I added a document-level JavaScript to a blank PDF (Toolbar Menu: Advanced > Document Processing > Document Javascripts). I named the function "showMyMessage" (with no parameters) and executed it through the JSObject by calling jso.showMyMessage() in my script. The script opened the document and executed the script successfully.

Perhaps if you post your code as to how you are acquiring the JSObject we may be able to help more. What you are trying to do clearly works so we need to figure out where the hiccup in your script is.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 26, 2008 Feb 26, 2008
PDL, ok, lets go and thanks a lot the help:

I am working with C# (Framework 2.0) and I need to invoke a Javascript code (inside my C# app) that signs a pdf document.
There is a Javascript code, that came with the Acrobat SDK documentation, that signs a pdf. The name of this file is sdkAddSignature.js. If you have the Acrobat 8.0 SDK documentation, you can find this file in the folder \\Adobe Adobe SDK 8.1\Acrobat 8 SDK\Version2\JavaScriptSupport\Samples\OutsidePDF\AddSignature.
I put this JS file inside the Acrobat javascript default folder: c:\Program Files\Adobe\Acrobat 8.0\Acrobat\Javascripts

I am creating my JSObject like below:

AcroAVDoc acroAVDoc = new AcroAVDoc();
Object jso = acroDoc.GetJSObject();

And now, I don't know how invoke the sdkAddSignature.js! I can't use jso.<method name>(<parameters>); This not works, because I need to invoke MY javascript code, and not a existing method in the Acrobat.dll

Any ideas to invoke the javascript code?

Sorry my questions, but I really need this informations and I'm not finding in the Acrobat documentation! Thanks!!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 26, 2008 Feb 26, 2008
Assuming you meant "Object jso = acroAVDoc.GetJSObject()" then there are several problems...

You need to load a document into your AcroAVDoc object in order to get it's JSObject. The JSObject will be null if no document has been loaded (JSObject is the JavaScript Doc class, so if there is no Doc ...)

If your sdkAddSignature.js is being loaded by Acrobat as a folder-level javascript, you can call functions you declared within the sdkAddSignature.js file through the JSObject. You just can't use a null JSObject.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 27, 2008 Feb 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!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 27, 2008 Feb 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();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 27, 2008 Feb 27, 2008
Hi PDL!!

It works here, but in VB.NET.
You really did it in C#?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 27, 2008 Feb 27, 2008
In many varied projects I have successfully used the IAC JSObject in VBScript, VB.NET and C#.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 28, 2008 Feb 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!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2008 Mar 03, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2008 Mar 03, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines