What a cool idea for a programmer’s book! Can’t resist — here is a ready-made script! (Enjoy disassembling it. Javascript itself is not very hard, but you got to make it interact just right with InDesign.)
For this to work, you have to assign a label to the text frame(s) that contain the Auto Page Number code on your Master Pages; select the FRAME, then use the Script Label panel (or the Layers panel in newer versions of InDesign) and assign the label “pn” — for ‘page number’. Then run the following script!
It will try to locate the labelled text frames for each page, override them when found, and change all Current Page Number markers into the correct, uppercased, hexadecimal form.
//DESCRIPTION:Change page numbers to Hex!
// A Jongware script 13-Oct-2014
app.findTextPreferences = null;
app.findTextPreferences.findWhat = "^N"; // Current Page Number
doc = app.activeDocument;
for (p=0; p<doc.pages.length; p++)
{
a_page = doc.pages[p];
pagenum = a_page.documentOffset - a_page.appliedSection.pageStart.documentOffset + a_page.appliedSection.pageNumberStart;
// who is your master then?
m = a_page.appliedMaster;
if (m && m.isValid)
{
for (f=a_page.masterPageItems.length-1; f>=0; f--)
{
if (a_page.masterPageItems[f].label == 'pn')
{
// we got one. Override it..
tf = a_page.masterPageItems[f].override (a_page);
// .. and change page number code ..
pgcode = tf.findText(true);
for (i=0; i<pgcode.length; i++)
{
pgcode[i].contents = (pagenum).toString(16).toUpperCase();
}
}
}
}
}