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

acrobat javascript 'addLink' not working properly in cropped pages.

Community Beginner ,
Feb 07, 2023 Feb 07, 2023

Copy link to clipboard

Copied

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.

 

 

TOPICS
Edit and convert PDFs , JavaScript

Views

462

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 ,
Feb 07, 2023 Feb 07, 2023

Copy link to clipboard

Copied

This document is weird, the page format is not indicated where it should be. Unlike other PDF documents.

 

Capture_2302071242.png

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 ,
Feb 07, 2023 Feb 07, 2023

Copy link to clipboard

Copied

Can you explain what you mean by 'the page format' ? I can see page dimensions where you indicated in the picture. I am working on ADOBE Acrobat Pro DC.

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 ,
Feb 07, 2023 Feb 07, 2023

Copy link to clipboard

Copied

Yes, you need to add to the rect an offset. I use the difference between the Crop and Trip boxes of the page for that, like this:

 

var cropBox = doc.getPageBox("Crop", p);
var trimBox = doc.getPageBox("Trim", p);
var xOffset = cropBox[0]-trimBox[0];
var yOffset = cropBox[1]-trimBox[1];
var r = [Number(r[4])+xOffset, Number(r[3])-yOffset, Number(r[2])+xOffset, Number(r[5])-yOffset];

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 ,
Feb 07, 2023 Feb 07, 2023

Copy link to clipboard

Copied

Thank you. But-
Since 'Media', 'Crop', 'Trim', 'Art'- all pageboxes are of same size, offset values are '0'. What to do now?

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 ,
Feb 07, 2023 Feb 07, 2023

Copy link to clipboard

Copied

Can you share the file with us, please?

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 ,
Feb 07, 2023 Feb 07, 2023

Copy link to clipboard

Copied

I have already shared the file. Please check. 

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 ,
Feb 08, 2023 Feb 08, 2023

Copy link to clipboard

Copied

I see it now. In this case the issue is with BBox. Calculate the offset between the Crop box and it, and see if that works.

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 ,
Feb 08, 2023 Feb 08, 2023

Copy link to clipboard

Copied

nope. not working

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 ,
Feb 08, 2023 Feb 08, 2023

Copy link to clipboard

Copied

The structure of this file is completely bonkers... Probably the fault of the application that created it.

Either re-create the file, or use the page width as the y-offset. That seems to produce good results, even though it doesn't make sense.

Like this:

 

 

	var cropBox = doc.getPageBox("Crop", p);
	var xOffset = 0;
	var yOffset = cropBox[2];
	return [Number(r[4])+xOffset, Number(r[3])-yOffset, Number(r[2])+xOffset, Number(r[5])-yOffset];

 

 

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 ,
Feb 08, 2023 Feb 08, 2023

Copy link to clipboard

Copied

LATEST

"Can you explain what you mean by 'the page format' ? I can see page dimensions where you indicated in the picture."

Imran25844166y4hb

Sorry, in French "page format" means "page dimensions" and so I often make this mistake.

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