Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Convert Page Number Placeholder into Text javascript

Enthusiast ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

Hi Pros, I found this script in (Creative Pro) Written by the Late Jongware in 2011, but it doesnt work at all in InDesign CC 2021, I think it need to be updated, but i dont know how, any help will be apperciated.

//DESCRIPTION:Convert Page Number Placeholder '#' into Text
// A Jongware Script 11-Dec-2011

var allPages = app.activeDocument.pages;
for (iterate=0; iterate<allPages.length; iterate++)
{
customPageNumber (allPages[iterate]);
}


function customPageNumber (aPage)
{
if (aPage.appliedMaster == null)
return;


pageSide = (aPage.side == PageSideOptions.RIGHT_HAND) ? 1 : 0;
masterFrame = findFrameContaining (aPage.appliedMaster, pageSide, '#');
if (masterFrame != null)
{
frame = findByLabel (aPage.pageItems, "page number");
if (frame != null)
{
frame.removeOverride();
}
frame = masterFrame.override (aPage);
frame.label = "page number";

placeholder = frame.contents.indexOf ('#');
if (placeholder != -1)
{
pageString = numberToText(Number(aPage.name));
pageString = pageString.substr(0,1).toUpperCase()+pageString.substr(1);
frame.characters[placeholder].contents = pageString;
}
}
}


function findFrameContaining (master, side, text)
{
var masterPage;
var i;

if (master.pages.length > 1)
masterPage = master.pages[side];
else
masterPage = master.pages[0];
for (i=0; i<masterPage.textFrames.length; i++)
{
if (masterPage.textFrames[i].contents.indexOf(text) > -1)
return masterPage.textFrames[i];
}
// Not found? Perhaps on this Master's Master?
if (master.appliedMaster != null)
return findFrameContaining (master.appliedMaster, side, text);
return null;
}


// Needed because the very useful label lookup was
// -- totally unnecessarily! -- removed in CS5+ ...
function findByLabel (items, label)
{
var i;
for (i=0; i<items.length; i++)
if (items[i].label == label)
return items[i];
return null;
}


function numberToText (number)
{
var ones = [ "zero", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen" ];
var tens = [ "zero", "ten", "twenty", "thirty", "fourty", "fifty",
"sixty", "seventy", "eighty", "ninety" ];
var result = '';


if (number < 0)
return "ha ha";
if (number == 0)
return ones[0];


if (number >= 1000)
{
thousand = Math.floor(number/1000);
result = numberToText (thousand) + " thousand";
number = number - 1000*thousand;
if (number > 0)
result = result + " ";
}


if (number >= 100)
{
hundred = Math.floor(number/100);
result = result + ones[hundred]+" hundred";
number = number - 100*hundred;
if (number != 0)
result = result + " and ";
}
if (number >= 20)
{
ten = Math.floor(number/10);
result = result + tens[ten];
number = number - 10*ten;
if (number != 0)
result = result + "-";
}
if (number != 0)
result = result + ones[number];
return result;
}

 Best Regards

M.Hasanain

Best
M.Hasanain
TOPICS
Scripting

Views

101

Likes

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

correct answers 1 Correct answer

Adobe Community Professional , Apr 09, 2021 Apr 09, 2021
It works for me in CC2020, so I would think it should work with CC2021. Are you getting an error or does nothing happen?

Likes

Translate

Translate
Adobe Community Professional ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

It works for me in CC2020, so I would think it should work with CC2021. Are you getting an error or does nothing happen?

 

Screen Shot 20.png

Screen Shot 21.png

Likes

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
Enthusiast ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

LATEST

actually i forget to change the page numbers to #, thank you for remembering me!

Best

M.Hasanain

Best
M.Hasanain

Likes

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