2019年3月3日日曜日

Indesignで隠しノンブルを一気に入れる時のスクリプト

Indesignで、目次までのページ番号をローマ数字で振って、それ以降は普通の数字でページ番号を振りたいということは多々あると思います。
一方で、印刷所に出すときは一貫したノンブルを隠しノンブルとして入れないといけないんですが、ページ数が多いと結構面倒です。
そういうわけで一貫した隠しノンブルを自動で挿入したいんですが、意外にそういうスクリプトを見つけられなくて困りました。
というわけで備忘録がてらおいておきます。

pdfに出力するぞ、というタイミングで使うのがオススメです

PageObj = app.activeDocument.pages;
pStyle = app.activeDocument.paragraphStyles.item("Normal");
a = [Justification.rightAlign,Justification.leftAlign] //右綴じの場合。左綴じは中身を入れ替える
for (i=0; i<PageObj.length; i++)
{
        total = PageObj[i].textFrames.add();
        w = app.activeDocument.documentPreferences.pageWidth;
        h = app.activeDocument.documentPreferences.pageHeight;
        top = h-8
        if (i==0) {
            x=3
            }else{
                x=w
            }

     
       total.visibleBounds = [top.toString() + " mm",(x+(Math.pow(-1, i+1))).toString()+" mm",h.toString()+" mm",(x+(Math.pow(-1,i+1)*4*4)).toString ()+"  mm"];
       total.contentType = ContentType.textType;
       total.contents = (i+1).toString();
     

       total.paragraphs[0].applyParagraphStyle(pStyle);
       total.paragraphs[0].justification = a[i%2];
}