• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Dec 28, 2017 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.

TOPICS
Acrobat SDK and JavaScript

Views

870

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
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 30, 2017 Dec 30, 2017

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 us

...

Votes

Translate

Translate
Community Expert ,
Dec 28, 2017 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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Beginner ,
Dec 29, 2017 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?

Votes

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
community guidelines
Community Expert ,
Dec 29, 2017 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.

Votes

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
community guidelines
Community Expert ,
Dec 30, 2017 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)

Votes

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
community guidelines
Community Beginner ,
Jan 09, 2018 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?

Votes

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
community guidelines
Community Expert ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

LATEST

- Waow! Happy 2018

- Multiple responses as correct: no

Votes

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
community guidelines