Placing Form Button over each Bullet in a Document (or finding string's coordinates on page)?

Community Beginner ,
Dec 28, 2017

Copy link to clipboard

Copied

Hello! ! I'm coming from different languages, just getting back into JavaScript, and struggling on this one...

I see how to JavaScript the placing of a Form Button on a page, including how to set its location...

https://acrobatusers.com/tutorials/js_add_buttons_to_pdf

...but I'm trying to figure out how to automatically place the button over each bullet in a document, for example.

How can I find the coordinates (so to speak) of specific text or character strings found within a document, such as using a method like this?
https://acrobatusers.com/tutorials/text-matching-regular-expressions

I'm using primarily Adobe Acrobat X Pro, but also Adobe Acrobat DC Pro.

Adobe Community Professional
Correct answer by JR Boulay | Adobe Community Professional

You should read the addLink chapter in the JavaScript™ for Acrobat® API Reference, it gives a nice sample that you can easily hack to fit your needs:

// Example 2

// Search through the document for the word “Acrobat” and create a link around that word.

for (var p = 0; p < this.numPages; p++)

{

var numWords = this.getPageNumWords(p);

for (var i=0; i<numWords; i++)

{

var ckWord = this.getPageNthWord(p, i, true);

if ( ckWord == "Acrobat")

{

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('http://www.example.com/')");

}

}

}

I started from this script it to create this free tool: https://www.abracadabrapdf.net/?p=7437

(With buttons form fields instead of Link objects since a Link cannot have an "underlined" border)

TOPICS
Acrobat SDK and JavaScript

Views

246

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Placing Form Button over each Bullet in a Document (or finding string's coordinates on page)?

Community Beginner ,
Dec 28, 2017

Copy link to clipboard

Copied

Hello! ! I'm coming from different languages, just getting back into JavaScript, and struggling on this one...

I see how to JavaScript the placing of a Form Button on a page, including how to set its location...

https://acrobatusers.com/tutorials/js_add_buttons_to_pdf

...but I'm trying to figure out how to automatically place the button over each bullet in a document, for example.

How can I find the coordinates (so to speak) of specific text or character strings found within a document, such as using a method like this?
https://acrobatusers.com/tutorials/text-matching-regular-expressions

I'm using primarily Adobe Acrobat X Pro, but also Adobe Acrobat DC Pro.

Adobe Community Professional
Correct answer by JR Boulay | Adobe Community Professional

You should read the addLink chapter in the JavaScript™ for Acrobat® API Reference, it gives a nice sample that you can easily hack to fit your needs:

// Example 2

// Search through the document for the word “Acrobat” and create a link around that word.

for (var p = 0; p < this.numPages; p++)

{

var numWords = this.getPageNumWords(p);

for (var i=0; i<numWords; i++)

{

var ckWord = this.getPageNthWord(p, i, true);

if ( ckWord == "Acrobat")

{

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('http://www.example.com/')");

}

}

}

I started from this script it to create this free tool: https://www.abracadabrapdf.net/?p=7437

(With buttons form fields instead of Link objects since a Link cannot have an "underlined" border)

TOPICS
Acrobat SDK and JavaScript

Views

247

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 28, 2017 0
Adobe Community Professional ,
Dec 28, 2017

Copy link to clipboard

Copied

Unfortunately I never wrote a tutorial on this topic. But, you'll find everything you'll need in the Acrobat JavaScript Reference.

Here is the page with the relavant function, doc.getPageNthWordQuads(). 

Acrobat DC SDK Documentation

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 28, 2017 1
Community Beginner ,
Dec 29, 2017

Copy link to clipboard

Copied

Awesome tutorials that you did write though, thank you so much!

This is EXACTLY what I was looking for.

But one more Q...

To get the word number N, I would have to iterate through the words with something like getPageNthWord() ?
Or is there a search function that can return the number N for a result?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 0
Most Valuable Participant ,
Dec 29, 2017

Copy link to clipboard

Copied

You would need to iterate over all the words in the page, unless of course you know in advance what N is, and then you can specify it directly.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 29, 2017 0
Adobe Community Professional ,
Dec 30, 2017

Copy link to clipboard

Copied

You should read the addLink chapter in the JavaScript™ for Acrobat® API Reference, it gives a nice sample that you can easily hack to fit your needs:

// Example 2

// Search through the document for the word “Acrobat” and create a link around that word.

for (var p = 0; p < this.numPages; p++)

{

var numWords = this.getPageNumWords(p);

for (var i=0; i<numWords; i++)

{

var ckWord = this.getPageNthWord(p, i, true);

if ( ckWord == "Acrobat")

{

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('http://www.example.com/')");

}

}

}

I started from this script it to create this free tool: https://www.abracadabrapdf.net/?p=7437

(With buttons form fields instead of Link objects since a Link cannot have an "underlined" border)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 30, 2017 1
Community Beginner ,
Jan 09, 2018

Copy link to clipboard

Copied

Wow... what a New Year's! I'm sorry for disappearing for a while... we just had our first child! Both mom and baby are doing great.

And you guys have been super helpful... can I mark multiple responses as correct?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 09, 2018 1
Adobe Community Professional ,
Jan 09, 2018

Copy link to clipboard

Copied

- Waow! Happy 2018

- Multiple responses as correct: no

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 09, 2018 0