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

Javascript to count the links in a pdf.

MSP
Registered: Sep 16 2008
Posts: 25
Answered

Hello,

I am very new to Javascript and Acrobat. I am sorry. I was wondering if there was a simple way to run a javascript to count the number of links in a document. I have a document which links to other places inside the document many, many times. I have to go throught and count them individually and it has gotten to be very tedious! I just found out about Javascript in acrobat and I think this could be a way to make this simpler. Thank you for your time!

MSP

MSP
Registered: Sep 16 2008
Posts: 25
Possibly Something to do with getLinks??
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Kudos to you for looking through the manuall first!!:)

Yes, the getLinks function returns an array of link object on a particular page. to count links just loop through the pages and add up the number fo links on each page. However, the link object doesn't provide much information. You can't get the link URL out of it, so you can't count links that point to a particular URL.

Here's a simple example:

var sum = 0;
for(var i=0;i

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

MSP
Registered: Sep 16 2008
Posts: 25
That is perfect! Exactly what I wanted.