0

I'm trying to write a simple script that looks at the active InDesign file and reports the page width and height. However, I have a multiple page document, and not all pages are the same size. So I cannot use the document page sizes. How do I read the individual page sizes?

here is my starting code:

#target "InDesign"

var doc=app.activeDocument;  

// set in inches
doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;  
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;

for(var j =0;j<doc.pages.length;j++)  
    { 

        // gather data
        var pageW=doc.documentPreferences.pageWidth;  
        var pageH=doc.documentPreferences.pageHeight;  

        // display
        //$.writeln("w: " + pageW + " h: " + pageH );
        
        $.writeln(doc.pages[j].name);
        $.writeln(doc.pages[j].properties);

    }

2 Answers2

0

Strike that. Found it.

#target "InDesign"

var doc=app.activeDocument;  

// set in inches
doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;  
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;

for(var j =0;j<doc.pages.length;j++)  
    { 

        // gather data
        var pageW=doc.documentPreferences.pageWidth;  
        var pageH=doc.documentPreferences.pageHeight;  

        // display
        //$.writeln("w: " + pageW + " h: " + pageH );
        
        $.writeln(doc.pages[j].name);     
        $.writeln("Page Width : " +  doc.pages[j].bounds[3] + "\rPage Height : " + doc.pages[j].bounds[2] );

    }
0

Just a followup. The above answer only works if there is no content in your slug area. The following is a better answer.

#target "InDesign"

var doc=app.activeDocument;  

// set in inches
doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;  
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;

$.writeln(doc.pages.item(0).marginPreferences.top);

for(var j =0;j<doc.pages.length;j++)  
    { 

        // gather data
        var pageW=doc.documentPreferences.pageWidth;  
        var pageH=doc.documentPreferences.pageHeight;  

        // write data
        $.writeln("Page : " + doc.pages[j].name);   
        $.writeln("  Page Width : " +  (doc.pages[j].bounds[3]-doc.pages[j].bounds[1]) + "\r  Page Height : " + (doc.pages[j].bounds[2] - doc.pages[j].bounds[0] ));

    }