Java Script - How to place an annotation on a form field

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Nebulo
User
Posts: 15
Joined: Fri Nov 21, 2008 10:27 pm

Java Script - How to place an annotation on a form field

Post by Nebulo »

I'd like to place a rectangular annotation on a form field (to make it more visible for a while). I know, that I can do it using JS like this one:

Code: Select all

var field = this.getField("Field_Name");
fr = field.rect;
var annot = this.addAnnot({
    page: field.page,
    type: "Square",
    name: field.name,
    rect: fr
  });
Everything is fine until there are two or more fields with the same name in the PDF and I want to place annotations on each one.
Base on "JavaScript for Acrobat API Reference" I should call field like this: this.getField("Field_Name.1"), this.getField("Field_Name.2"). Unfortunately it doesn't work.
Please tell me how can I do it. There is test.pdf in attachment containing fields with the same names which I'm using for tests.

Sincerely Nebulo
You do not have the required permissions to view the files attached to this post.
User avatar
Chris - PDF-XChange
Site Admin
Posts: 798
Joined: Tue Apr 14, 2009 11:33 pm

Re: Java Script - How to place an annotation on a form field

Post by Chris - PDF-XChange »

Hi Nebulo,

Are you using an SDK? If so you have posted your question in the wrong forum. If you are just running javascript in the enduser product, please let me know and I will ask the appropriate person to answer your question, thanks.

Chris
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.


Chris Attrell
Tracker Sales & Support North America
http://www.tracker-software.com
Nebulo
User
Posts: 15
Joined: Fri Nov 21, 2008 10:27 pm

Re: Java Script - How to place an annotation on a form field

Post by Nebulo »

Hi Chris,

Yes, I am using SDK (PDF XChange Viewer SDK 2.0 Build 57). Sorry for the mistake. Can my post be moved to the proper place?

Regards Nebulo
User avatar
Paul - PDF-XChange
Site Admin
Posts: 7371
Joined: Wed Mar 25, 2009 10:37 pm

Re: Java Script - How to place an annotation on a form field

Post by Paul - PDF-XChange »

H Nebulo

I have moved your topic to the Viewer SDK forum. Did you get this working or do you still need help?

regards
Best regards

Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
Nebulo
User
Posts: 15
Joined: Fri Nov 21, 2008 10:27 pm

Re: Java Script - How to place an annotation on a form field

Post by Nebulo »

Thanks Paul,

No I didn't. I still need help.
BTW: I've also tried a 2.5 BETA - still nothing.

Regards Nebulo
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

Re: Java Script - How to place an annotation on a form field

Post by Stefan - PDF-XChange »

Hello again Nebulo,

I have asked the dev guys to have a look at this topic as well.
We will reply here as soon as we have any info.

Best,
Stefan
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3586
Joined: Thu Jul 08, 2004 10:36 pm

Re: Java Script - How to place an annotation on a form field

Post by Ivan - Tracker Software »

Base on "JavaScript for Acrobat API Reference" I should call field like this: this.getField("Field_Name.1"), this.getField("Field_Name.2"). Unfortunately it doesn't work.
Fixed
PDF-XChange Co Ltd. (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: Java Script - How to place an annotation on a form field

Post by Vasyl - PDF-XChange »

Hi, Nebulo.

In the new build you will be able to use the next code:

Code: Select all

for (var i = 0; i < this.numFields; i++)
{
 var fn = this.getNthFieldName(i);
 console.println("Field[" + i + "] = " + fn);
 for (j = 0; j < 10; j++)
 {
  var f = this.getField(fn + "." + j);
  if (f == null)
   break;
  var a = this.addAnnot({ page: f.page,
        type: "Square",
        name: f.name,
        rect: f.rect});
    if (a != null) 
       a.readOnly = true;
  }
}
The current build (189) contains one bug in Document::getField(<name> + "." + <IndexOfWidget>) case... :(
Wait for next build.

Best
Regards.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.