Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Change page number style depending on page

Return to Member Forum

  • Author
    Posts
    • #89044
      Anonymous
      Inactive

      Hello,

      I have a document that is 24 pages long.

      I am trying to create a page number style where you can see numbers 1-24 across the bottom of the page on every page. Depending on what page you’re on, I want that page highlighted/in a different style. For example every number would be a light grey and if I’m on page 5 then the number ‘5’ would be bold and in red, then on page 6 the number ‘5’ would go back to light grey and ‘6’ would be now bold and red. I know I could do this by manually changing the style on every page but I wanted to see if there’s a way of automatically doing this. I tried exploring text variables but couldn’t get it to work. Any ideas?

    • #89048
      Matt Isaac
      Participant

      The only way i know of to do this is with scripting. There may or may not be a way using InDesign’s built-in features. create a paragraph style with the styling the way you want all the numbers to appear and name that style “Page Numbering”, then create a character style the way you want the current page number to be formatted and name this style “Current Page” and run this script:

      
      /*
      Scripted by Skemicle
      1:00 PM 10/17/2016
      */
      if (parseFloat(app.version) < 6)
      main();
      else
      app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Add page numbers in reverse");
      function main() {
      	doc = app.activeDocument;
      	prefs = doc.viewPreferences;
      	hmu = prefs.horizontalMeasurementUnits;
      	vmu = prefs.verticalMeasurementUnits;
      	prefs.horizontalMeasurementUnits = MeasurementUnits.INCHES;
      	prefs.verticalMeasurementUnits = MeasurementUnits.INCHES;
      	var ro = doc.viewPreferences.rulerOrigin;
      	doc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
      	page = doc.pages;
      	pages = [];
      	userlayer = doc.activeLayer;
      	try{
      		doc.layers.itemByName("Page Numbering").remove()
      	}catch(er){};
      	doc.layers.add({name:"Page Numbering"});
      	pageHeight = doc.documentPreferences.pageHeight;
      	pageWidth = doc.documentPreferences.pageWidth;
      	leftMargin = doc.marginPreferences.left;
      	rightMargin = pageWidth - doc.marginPreferences.right;
      	bottomMargin = pageHeight - doc.marginPreferences.bottom;
      	for(c=0;c<page.length;c++){
      		pages[c] = c + 1
      	}pageNumbers = pages.join(" ");
      	for(c=0;c<page.length;c++){
      		numbersFrame = page[c].textFrames.add({contents:pageNumbers, geometricBounds:[bottomMargin,leftMargin,bottomMargin + .25,rightMargin]});
      		numbersFrame.insertionPoints[0].appliedParagraphStyle = "Page Numbering";
      		word = numbersFrame.words
      		for(n=0;n<word.length;n++){
      			if(word[n].contents == c + 1){
      				word[n].appliedCharacterStyle = "Current Page";
      			}
      		}
      	}
      	doc.layers.itemByName("Page Numbering").locked = true;
      	app.activeDocument.activeLayer = userlayer;
      	doc.viewPreferences.rulerOrigin = ro;
      	prefs.horizontalMeasurementUnits = hmu;
      	prefs.verticalMeasurementUnits = vmu;
      }
      

      For information on installing and using this script see: https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post.php

    • #89084
      Anonymous
      Inactive

      Thank you for providing. I thought scripting might be the way but have no experience in it.

      Unfortunately it didn’t work, I received an error:
      “Error String: No matching closing brace found”
      “Line: 9”
      “Source: function main() {”
      “Offending Text: {”

      Appreciate any advice you can give.

    • #89087
      Matt Isaac
      Participant

      I’m guessing when you copy/pasted the code you didn’t include the last ‘}’ add that to the end of the script.. also line 8, the line starting with app.doScript, I would change “Add page numbers in reverse” to just “Add page numbers” I copied the doScript function from a previous script i had written and forgot to edit that part.

    • #89108

      Hi Skemicle, nice! ;-)

      … The problem with this “text” approach is that if the “active page” number has a bigger size, the list won’t be really aligned page after page.
      Another point: if you want to add effects on the “active page” number, we can’t do it!

      (^/)

Viewing 4 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads