Programatically create annot line as dimension

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

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

Post Reply
chrisbouwman
User
Posts: 8
Joined: Fri Apr 12, 2013 5:56 am

Programatically create annot line as dimension

Post by chrisbouwman »

JavaScript does not create annotation at specified position:
var annot = this.addAnnot({type: "Line"});
annot.setProps({
borderEffectIntensity:0,
borderEffectStyle: "S",
intent: "LineDimension",
opacity: 1,
page: 0,
refType: "R",
strokeColor: "RGB,1,0,0",
style: "S",
leaderExtent: 5,
leaderLength: 100,
rect: [499,866,743,949],
points: [499,884,504,949],
arrowBegin: "ClosedArrow",
arrowEnd: "ClosedArrow",
width: 1
});

An annotation is created at 0,0,0,0. Another annotation with style "Text" is created at the proper location.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19673
Joined: Mon Jan 12, 2009 8:07 am
Contact:

Re: Programatically create annot line as dimension

Post by Stefan - PDF-XChange »

Hello chrisbouwman,

You have some errors in the code above. That's why it is not working.

the first is that you have leaderExtent when the correct should be
leaderExtend

And the second is the way you are specifying the points - the correct should be two sets of two values closed in brackets:
points: [[400,400],[550,500]]

So here's a proper sample that creates a correct measurement:

Code: Select all

var annot = this.addAnnot({
   page: 0,
   type:"Line",
   borderEffectIntensity:0,
   borderEffectStyle: "S",
   intent: "LineDimension",
   opacity: 1,
   refType: "R",
   strokeColor: "RGB,1,0,0",
   style: "S",
   leaderLength: 100,
   leaderExtend: 5,
   rect: [400,400,550,500],
   points: [[400,400],[550,500]],
   arrowBegin: "ClosedArrow",
   arrowEnd: "ClosedArrow",
   width: 1
});
chrisbouwman
User
Posts: 8
Joined: Fri Apr 12, 2013 5:56 am

Re: Programatically create annot line as dimension

Post by chrisbouwman »

Hello Stefan,

Thank you for the fast solution. The two sets of closed brackets did the trick. Strangely, for me it must be leaderExtent instead of leaderExtend. Nevertheless, it works fine now!
User avatar
⚜ Kenny Lemens, P.E. ᵂᴵ
User
Posts: 33
Joined: Thu Jan 23, 2025 4:09 pm

Re: Programatically create annot line as dimension

Post by ⚜ Kenny Lemens, P.E. ᵂᴵ »

Greetings,

Much appreciated! However, I spent a fair bit of time on this trying to get the color to 'work,' you would need to specify the stroke color as an array; you cannot sent is as a mere string:

Code: Select all

strokeColor:["RGB",0,85/255,0],

May this be of Good Help;
⚜ Kenny Lemens, P.E. ᵂᴵ
User Plugins: https://forum.pdf-xchange.com/viewtopic.php?t=42190&#:~:text=Drawing%20tools
[Migration] Revu Bluebeam 17 to PDF-XChange Editor: viewtopic.php?p=189798#p189798
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10586
Joined: Wed Jan 03, 2018 6:52 pm

Re: Programatically create annot line as dimension

Post by Daniel - PDF-XChange »

Hello, ⚜ Kenny Lemens, P.E. ᵂᴵ

That is how the API specifies StrokeColor should be used, Color arrays are directly referred to here:
image.png
image(1).png
You can follow this link to read more about them:
https://opensource.adobe.com/dc-acrobat ... lor-arrays

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Post Reply