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

How add page number as hyperlink with scripts

Community Beginner ,
Apr 24, 2017 Apr 24, 2017

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?

TOPICS
Scripting
1.4K
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
People's Champ ,
Jun 23, 2017 Jun 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

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 ,
Jun 23, 2017 Jun 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

Capture d’écran 2017-06-23 à 12.51.53.png

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 ,
Jun 23, 2017 Jun 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

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
People's Champ ,
Jun 23, 2017 Jun 23, 2017
LATEST

Voilà

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 ,
Jun 23, 2017 Jun 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

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