InDesign Javascript - Document Dimensions Width and Height In Pixels or Any Unit
Looking up how to get document dimensions in pixels but coming up empty. Just sharing this function I created as InDesign can be a bit verbose. Compared to photoshop converting dimensions is not as straightforward since InDesign doesn't include the unit of measurement.
Edit, updated function based on @rob day's solution
function idDocDims(doc){
app.scriptPreferences.measurementUnit = MeasurementUnits.PIXELS;
var w = doc.documentPreferences.pageWidth;
var h = doc.documentPreferences.pageHeight;
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;
return {w:w,h:h}
}
alert(idDocDims(app.activeDocument).w+" - "+idDocDims(app.activeDocument).h);
Olde Solution:
function idDocDims(doc,unit){var w = doc.documentPreferences.pageWidth;var h = doc.documentPreferences.pageHeight;var wU = doc.viewPreferences.horizontalMeasurementUnits;var hU = doc.viewPreferences.verticalMeasurementUnitsvar wPX = UnitValue(w,wU).as(unit);var hPX = UnitValue(h,hU).as(unit);return [wPX,hPX]}alert(idDocDims(app.activeDocument,"px"));

