Known Participant
February 7, 2023
Question
acrobat javascript 'addLink' not working properly in cropped pages.
- February 7, 2023
- 3 replies
- 2440 views
I have a 3 page file with pages of differently cropped sizes. Now I want to search through the document for the word “purchase” and create a link around that word. I am using this code below:
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 == "purchase")
{
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/')");
}
}
}The problem is: the links are not created properly. When I zoom out the pages, I see the links are created outside the cropped pages. How to fix this?
I have another issue:
If I click "Edit PDF", I see empty textboxes outside the cropped areas. These are probably from the original pages. I cropped these pages using "this.setPageBoxes: 'Media'" in javascript. Is there any way to remove these textboxes using javascript?
I am attaching a sample file for reference.
