var doc = app.activeDocument; // Cache the original ruler origin. var originalRulerOrigin = doc.viewPreferences.rulerOrigin; // Set the ruler origin to `page`, and set ruler XY offset to zero. doc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN; doc.zeroPoint = [0,0]; // Cache the original ruler units. var originalXUnits = doc.viewPreferences.horizontalMeasurementUnits; var originalYUnits = doc.viewPreferences.verticalMeasurementUnits; // Set the horizontal and vertical ruler units to millimeters. doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS; doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS; /** * Process each Text Frame and act on it as necessary according to its x1 and y1 coordinate. * @param {Object} pageRef - A reference to the page to be processed. */ function handleTextFrames(pageRef) { var allTextFrames = pageRef.textFrames.everyItem().getElements(); // Loop over each text frame... for (var i = 0, max = allTextFrames.length; i < max; i++) { var currentTextFrame = allTextFrames[i]; // Obtain the text frames x1 and y1 coordinate. var currentTextFrameBounds = currentTextFrame.geometricBounds; var y1 = currentTextFrameBounds[0]; var x1 = currentTextFrameBounds[1]; // Begin targeting specific text frames based on geometry... // 1. Delete a Text Frame if its : // - x1 coord is less than or equal to 15mm and // is greater than or equal to 10mm. // - y1 coord is less than or equal to 15mm and // is greater than or equal to 10mm. if (x1 <= 15 && x1 >= 10 && y1 <= 15 && y1 >= 10) { currentTextFrame.remove(); } // 2. Do something else with a Text Frame when its : // - x1 coord is less than or equal to 15mm and // is greater than or equal to 10mm. // - y1 coord is less than or equal to 70mm and // is greater than or equal to 60mm. if (x1 <= 15 && x1 >= 10 && y1 <= 70 && y1 >= 60) { // --> Do soemthing here... } // 3. Do more conditional checks .... } } // Loop over each page for (var i = 0, max = doc.pages.length; i < max; i++) { var currentPage = doc.pages[i]; handleTextFrames(currentPage); // Begin processing each text frame on each page. } // Restore rule origin doc.viewPreferences.rulerOrigin = originalRulerOrigin; // Restore ruler units doc.viewPreferences.horizontalMeasurementUnits = originalXUnits; doc.viewPreferences.verticalMeasurementUnits = originalYUnits;