These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Unable to add/ modify stamp programmatically.

premartha
Registered: Dec 7 2009
Posts: 3

hi,

I am using Acrobat 7.0.

Using C# and Interop.Acrobat.dll I am accessing JSObject of the pdf and trying to add a stamp to the pdf which is not working fine. I, however, successfully managed with inserting watermarks.

It always adds the default "draft" stamp but I cannot modify it using javascript and "AP" property of the annotation object.

Following is my code snippet,

public static int Stamp(string fileToMark, string outputFile, string author, string contents, string subject, Color color)
{
................
............

.....

for (int i = 0; i < oNumPages; i++)
{
annotObj = T.InvokeMember(
"AddAnnot",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, jsObj, null);
Type annotType = annotObj.GetType();
propsObj = annotType.InvokeMember(
"getProps",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, annotObj, null);
Type propsType = propsObj.GetType();

//start setting properties.
//type property
object[] typeParam = { "Stamp" };
propsType.InvokeMember(
"Type",
BindingFlags.SetProperty |
BindingFlags.Public |
BindingFlags.Instance,
null, propsObj, typeParam);

//page number property
object[] pageParam = { i };
propsType.InvokeMember(
"page",
BindingFlags.SetProperty |
BindingFlags.Public |
BindingFlags.Instance,
null, propsObj, pageParam);

.........................

..............

//annotation name property
object[] nameParam = { "PWAnno" };
propsType.InvokeMember(
"name",
BindingFlags.SetProperty |
BindingFlags.Public |
BindingFlags.Instance,
null, propsObj, nameParam);

object[] setPropsParam = { propsObj };
annotType.InvokeMember(
"setProps",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, annotObj, setPropsParam);
/////////////////////////////////////////////

//object[] getAnnotParam = { i, "PWAnno" };
//annotObj = T.InvokeMember(
// "getAnnot",
// BindingFlags.InvokeMethod |
// BindingFlags.Public |
// BindingFlags.Instance,
// null, jsObj, getAnnotParam);

//annotType = annotObj.GetType();

//now that stamp is already created and added to document, getProps needs to be revoked so that this time we can get reference of "AP" property
propsObj = annotType.InvokeMember(
"getProps",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, annotObj, null);

propsType = propsObj.GetType();

//annotation appearance property
object[] APParam = { "confidential" };
propsType.InvokeMember(
"AP",
BindingFlags.SetProperty |
BindingFlags.Public |
BindingFlags.Instance,
null, propsObj, APParam);

object[] setPropsParam2 = { propsObj };
annotType.InvokeMember(
"setProps",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, annotObj, setPropsParam2);

}
........
........

return 0;
}

As you can see I tried to modify the "AP" property to "Confidential" but it always puts "draft" stamp in it which is the default.

Kindly help me.

Regards,
Nikhil.

My Product Information:
Acrobat Pro 7.1.4, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
First, Never, ever post this much code. No one is going to read it. In fact this is a good way to NOT get your question answered. Post only the relavent points.

The AP property has to be set to the actual Stamp name. There are three confidential stamps. On the Standard Business list the name is "SBConfidential", There's also one named just "Confidential", and the one on the Dynamic stamps named "#DConfidential".

All of these work for me.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

premartha
Registered: Dec 7 2009
Posts: 3
hi Thom, thank you very much for your reply and a nice advice, I will keep in mind to follow your suggestion of pasting only the most relevant code in future :)

However, none of the names of the stamp mentioned by you work for me. I was just trying "confidential", infact not even a single stamp name works for me. It always inserts the "draft" stamp no matter what name of the stamp I supply, even if I give an absurd one!!

The most relevant piece of code used by me in this regards is,

propsObj = annotType.InvokeMember(
"getProps",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, annotObj, null);

propsType = propsObj.GetType();

object[] APParam = { "SBConfidential" };
propsType.InvokeMember(
"AP",
BindingFlags.SetProperty |
BindingFlags.Public |
BindingFlags.Instance,
null, propsObj, APParam);

object[] setPropsParam2 = { propsObj };
annotType.InvokeMember(
"setProps",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, annotObj, setPropsParam2);

Is there some other way, if needs to be achieved using C# and JSObject in SDK?

Regards,
Nikhil.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I've never tried to use the IAC API with C#, but I have used it with VB.NET so I know that it does work with the .NET framework. I don't know about your methodology. Since you're getting a stamp you are obviously invoking something. I've had problems in the past with passing objects into JSO calls. I try to stick with scaler types. So I would suggest a different approach.

Test out the JS code you want to use in the Acrobat JavaScript Console first and make sure it all works as expected. Then put all the code into a folder level function and make sure you can run that function from a button on a PDF, i.e. so that you know it will work in a document context. Then call this function from your C# code. This approach will massively simplify the C# programming and put all the JS calls in the Acrobat environment where they belong. No setting object properties from .NET.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

abhijeet
Registered: Jul 30 2011
Posts: 1
I am facing same problem that premartha has...

Any Help, I tried all the solution as above post but no success.

Please help me here...