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

How to create dynamic web url links using getURL

Thusi
Registered: Dec 14 2011
Posts: 3
Answered

Hello All,
 
I am hoping someone can help me with this. I am creating a script that searches for course codes and then creates a link to the registration page for each code found on a pdf document. The links are dynamic so I am passing the links in a string variable to the getURL method as follows.
  
if ( ckWord == CourseCode[k])
{
console.println(ckWord);
var urlstring = URLArray[k].toString();

var q = this.getPageNthWordQuads(p, i);
// Convert quads in default user space to rotated
// User space used by Links.
m = (new Matrix2D).fromRotated(this,p);
mInv = m.invert()
r = mInv.transform(q)
r=r.toString()
r = r.split(",");
l = addLink(p, [r[4], r[5], r[2], r[3]]);
l.borderColor = color.red;
l.borderWidth = 1;
l.setAction("this.getURL(urlstring)");

}
 
My problem is that the url is showing up with the local path in front of it. For example, it appears as f:\\|C:\...\http:\\wwww... etc. If I type the url into the getURL method it works just fine. Can someone please help guide me in passing dynamic links.
 
Thank you,
 
Thusi

My Product Information:
Acrobat Pro 10.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
First of all, maybe it would be better to use app.launchURL() instead of getURL(). The former will open the URL in the browser. The latter will try to convert the URL into a PDF file, and therefore won't work in Reader.

Secondly, there's an error in your code. If you want to use the value of urlstring, then you need to use it like this:
l.setAction("app.launchURL(\"" + urlstring + "\")");

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Thusi
Registered: Dec 14 2011
Posts: 3
try67 wrote:
First of all, maybe it would be better to use app.launchURL() instead of getURL(). The former will open the URL in the browser. The latter will try to convert the URL into a PDF file, and therefore won't work in Reader.Secondly, there's an error in your code. If you want to use the value of urlstring, then you need to use it like this:
l.setAction("app.launchURL(\"" + urlstring + "\")");
Thank you for your quick reply. When I try the line above I am getting this error.

SyntaxError: unterminated string literal
1:Link:Mouse Up.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
Go into the link and check what the action code is... Maybe your urlstring contains some invalid characters that needs to be escaped?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Thusi
Registered: Dec 14 2011
Posts: 3
Yes I just needed to call encodeURI with the url and then use it and it works. Thank you for all of your help.