Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Script to Auto-Adjust Page Length based on content

Return to Member Forum

  • Author
    Posts
    • #14406135
      Matthew Paquette
      Participant

      I’ve got a 130 page document that I’ve created via data merge. Each page contains 1 text frame that stretches vertically based on content. I’m looking for a script that will auto-size the pages to the size of the text frame. Does that exist?

      Thanks so much all!

      Matt

    • #14406136
      Nick Passmore
      Participant

      I don’t know offhand whether there is a script “in the wild” that will do this but it’s certainly scriptable.

      Are you working on MacOS or Windows?

      Is there only one text frame per page?

      And is the text frame on each page already expanded to fit the content?

      Is the stretch to be height only or width only or both?

      Do some pages need to be made smaller?

      Nick Passmore

    • #14406137

      Just For Fun! …

      https://snipboard.io/3iCQpY.jpg

      By Script of course:

      /*
      _FRIdNGE-0758_ResizePageOnTextFrame.jsx
      Script written by FRIdNGE, Michel Allio [04/09/2024]
      */

      app.doScript(“main()”, ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, “Resize Page On Text Frame! …”);

      function main() {

      app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

      var myDoc = app.activeDocument;
      myDoc.zeroPoint = [0,0];
      myDoc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

      var myPages = myDoc.pages,
      P = myPages.length, p;

      for ( p = 0; p < P; p++ ) {
      var myPage = myPages[p];
      myPage.marginPreferences.properties = {top: 0, left: 0, bottom: 0, right: 0};
      var myTFrame = myPage.textFrames[0];
      myTFrame.move([0,0]);
      var myPageWidth = myTFrame.geometricBounds[3]-myTFrame.geometricBounds[1];
      var myPageHeight = myTFrame.geometricBounds[2]-myTFrame.geometricBounds[0];
      myPage.resize(BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS, AnchorPoint.TOP_LEFT_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [myPageWidth, myPageHeight]);
      }

      alert( “Done! …\rby FRIdNGE, Michel Allio [04/09/2024]” )

      }

      (^/) The Jedi

      • #14406983
        Mike Rankin
        Keymaster

        Thanks for posting this, Michel. Unfortunately, I can’t get it to work. Here’s the error:

        JavaScript Error!
        Error Number: 45 Error String: Object is invalid
        Engine: main File: /Users/mike/Library/Preferences/Adobe InDesign/Version 19.0/ en_US/Scripts/Scripts Panel/Layout Scripts / ResizePageOnTextFrame.jsx Line: 6 Source: app.doScript”main)”, ScriptLanguage.javascript, undefined, UndoModes. ENTIRE_SCRIPT, “Resize Page On Text Frame! …”);

        This forum makes the code look like it has smart quotes but it doesn’t in the script, so that’s not the problem.

      • #14407001
      • #14407004
        Mike Rankin
        Keymaster

        Ok, I got it to work. The problem wasn’t in the code, it was that my document didn’t have a primary text frame. Thanks.

      • #14407008
        David Blatner
        Keymaster

        Bonjour Michel! In the future, please put the “pre” or “code” html tags before and after your code, and then our site will not change the quotes.

        For example, here is
        "some"
        text inside pre tags.
        

        :-D

    • #14406963
      James Dempsey
      Participant

      SizePageToThing is a free script – you would just select the frame on the page and run the script. Only does one page at a time though.

      Free InDesign Scripts

Viewing 3 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads