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

Changing path of open a doc in links using javascript

New Here ,
Mar 03, 2022 Mar 03, 2022

I have a pdf with 1 page, but 300 links. I copy and pasted the pdf to a new location and all the links broke. After investigating this is due to it looking for the file in my new path rather than the path i set initially.

I am fairly new to using javacript in adobe.   According to my research, the action of the current links cannot be changed using javascript, therefore i believe the best approach would be to destroy and remake the link.  Currently each box link is above the text of the file name, so i believe the process would be:

find link location, delete

for (var page = 0; page < this.numPages; page++)
{
var box = this.getPageBox("Crop", page);
this.removeLinks(page, box);
}

ocr the inside for the page name, save to var

       Not sure how to do this part, save as constant DocName   

set base path as a constant

var basePath = 'C/users/.../';

create link using new path

var linkWidth = 36, linkHeight = 18;
for (var i = 0; i < this.numPages; i++)
{
// Create the coordinates for the left link:
var Rect = [0, linkHeight, linkWidth, 0];
// Create the coordinates for the right link:
var cropBox = this.getPageBox("Crop", i);
var offset = cropBox[2] - cropBox[0] - linkWidth;
var rRect = [offset, linkHeight, linkWidth + offset, 0];
// Create the Link objects:
var NewLink = this.addLink(i, Rect);
NewLink.setAction("app.openDoc(basePath + DocName);");
// Customize the link appearance:
NewLink.borderColor = color.blue;
NewLink.borderWidth = 1;
}

Thats all i have thus far, any help would be appreciated. If you have an easier way

TOPICS
Edit and convert PDFs
772
Translate
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 ,
Mar 03, 2022 Mar 03, 2022

What is the value of DocName? Where should it come from?

And you can't refer to basePath in the code. That variable doesn't exist within that context.

You need to insert its value as a string to the openDoc command.

 

I would recommend you don't do that at all, though. If you want to edit your links a script is not the way to go.

You can do it using a stand-alone tool (or maybe a plugin), much more easily, and it won't be limited to just JS-based actions. For example, this (paid-for) tool I've developed will allow you to easily edit all the File-links in your file: https://www.try67.com/tool/batch-edit-file-links-in-pdf-files

 

Translate
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
New Here ,
Mar 04, 2022 Mar 04, 2022

@try67 docname refers to the document name such as 1-3.pdf.

While I appreciate your offer to buy your tool, my intention is to learn how to create my own tools. Are there any manuals on how to create plugins and/or which commands to use to replicate my purpose? There seems to be a lack of information and any advice you could give to achieve my goal would be appreciated

Translate
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 ,
Mar 06, 2022 Mar 06, 2022
LATEST

It's all documented in the Acrobat SDK: https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/

Personally, I use a third-party PDF library for this kind of task, not a plugin.

Translate
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