Skip to main content
sohrabs6818113
Participant
April 24, 2017
Question

How add page number as hyperlink with scripts

  • April 24, 2017
  • 2 replies
  • 1390 views

Hi

I have this script

found[0].contents = finds[0].parentTextFrames[0].parentPage.name; 

which It puts the page number in a field.

is it anyway to make this number hyperlink? it means when click on number goes to the page?

This topic has been closed for replies.

2 replies

Alexandre Becquet
Community Expert
Community Expert
June 23, 2017

And the 3nd solution :

Go to text menu, choose Hyperlink and Cross-references

Choose the link type, page in this case

You can choose the document

Choose the page Number

Choose a zoom type if you want

And voilà !!

I hope you Will find the answer betweem this 3 options

Loic.Aigon
Legend
June 23, 2017

Try this :

var main = function(paragraph) {

var doc = app.properties.activeDocument, pages, names = [], page,

n = 0, i = 0, tf, text, source, destination, hyperlink;

if ( !doc ) return;

tf = doc.pages[0].textFrames.add();

pages = doc.pages.everyItem().getElements();

n = pages.length;

while ( i<n ) {

tf.parentStory.recompose();

page = pages;

tf.parentStory.insertionPoints[-1].contents = page.name;

tf.parentStory.recompose();

tf.overflows && tf.fit( FitOptions.FRAME_TO_CONTENT );

text = tf.parentStory.lines[-1];

source = doc.hyperlinkTextSources.add( text );

destination = doc.hyperlinkPageDestinations.add( page );

doc.hyperlinks.add ( source, destination, {name:"Go to page "+page.name } );

i<n && tf.parentStory.insertionPoints[-1].contents ="\r";

i++;

}

}

var u;

app.doScript ( "main(app.activeDocument.stories[0].paragraphs[-1])",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );

But I have this feeling that should be achievable through standards features :S

HTH anyway

Loic

Alexandre Becquet
Community Expert
Community Expert
June 23, 2017

Yes this feature already existe

Just select the page Number and choose hyperlink in the panel to add it

It's a screenshot about the French Version

Alexandre Becquet
Community Expert
Community Expert
June 23, 2017

I think the best technique to answer your question and turn the numbering boc into a button is choose the action "Go to the next page"

Interactive: Convert to Button

Apply the action you want

See the result in Pub preview