Skip to main content
Known Participant
January 11, 2025
Answered

Auto page height size

  • January 11, 2025
  • 7 replies
  • 1899 views

Hi, In InDesign, I want to display each article on a separate page. The page height should automatically adjust vertically based on the length of the text. My heading style is set to "Start in Next Frame."

 

Thank you for your help and rights.

Correct answer Peter Kahrel

Fun thing to do. Here's a script. To use it, place the cursor in any of the TITLE 1 headings, then run it.

 

The idea is (1) if an article is in one frame, fit the frame to the text, then set the height of the page so that its bottom is 24 points below the text frame. You can change that value. Should probably be the bottom margin.

(2) if an article is in two or more frames, make its first frame insanely tall, to expose the whole article in one frame, then do as in (1) -- resize the frame, then resize the page.

 

P.

 

#targetengine fitPagesToArticles

// Place the cursor in any of the heading paragraphs
// the run the script

// resize() requires points
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

pageWidth = app.activeDocument.documentPreferences.pageWidth;

app.findTextPreferences = null;

try {
  app.findTextPreferences.appliedParagraphStyle = app.selection[0].appliedParagraphStyle;
} catch (_) {
  alert ('Place the cursor in the heading style');
  exit();
}

headings = app.activeDocument.findText();

for (i = 0; i < headings.length; i++) {
  
  frame = headings[i].parentTextFrames[0];
  page = frame.parentPage;

  gb = frame.geometricBounds;
  
  // We consider ranges from one heading to
  // the next. Therefore the last heading
  // ranges to the end of the story
  
  if (i === headings.length-1) {
    // The last heading: the end of the range
    // is the story's last frame
    lastFrame = frame.endTextFrame;
  } else {
    // Not the last heading: the end of the range
    // is up to the next heading
    lastFrame = headings[i+1].parentTextFrames[0];
  }

  if (frame.nextTextFrame != lastFrame) {
    // The article is in more than one text frame.
    // Force the article into one frame
    // by making its first frame very tall
    gb[2] = gb[0]+20000;
    frame.geometricBounds = gb;
  }

  // Set the bottom of the frame to the last baseline
  gb[2] = frame.lines[-1].baseline;
  frame.geometricBounds = gb;
    
  page.resize (CoordinateSpaces.INNER_COORDINATES,
    AnchorPoint.TOP_CENTER_ANCHOR,
    ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
    [pageWidth, gb[2]+24]
  );
}

 

 

7 replies

Robert at ID-Tasker
Legend
January 11, 2025

@uniq1

 

Any chance you can share a sample file? 

 

uniq1Author
Known Participant
January 12, 2025

Hi @Robert at ID-Tasker I probably won't need to send any files. Peter Kahrel's script is perfect for that purpose.

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
January 11, 2025

Fun thing to do. Here's a script. To use it, place the cursor in any of the TITLE 1 headings, then run it.

 

The idea is (1) if an article is in one frame, fit the frame to the text, then set the height of the page so that its bottom is 24 points below the text frame. You can change that value. Should probably be the bottom margin.

(2) if an article is in two or more frames, make its first frame insanely tall, to expose the whole article in one frame, then do as in (1) -- resize the frame, then resize the page.

 

P.

 

#targetengine fitPagesToArticles

// Place the cursor in any of the heading paragraphs
// the run the script

// resize() requires points
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

pageWidth = app.activeDocument.documentPreferences.pageWidth;

app.findTextPreferences = null;

try {
  app.findTextPreferences.appliedParagraphStyle = app.selection[0].appliedParagraphStyle;
} catch (_) {
  alert ('Place the cursor in the heading style');
  exit();
}

headings = app.activeDocument.findText();

for (i = 0; i < headings.length; i++) {
  
  frame = headings[i].parentTextFrames[0];
  page = frame.parentPage;

  gb = frame.geometricBounds;
  
  // We consider ranges from one heading to
  // the next. Therefore the last heading
  // ranges to the end of the story
  
  if (i === headings.length-1) {
    // The last heading: the end of the range
    // is the story's last frame
    lastFrame = frame.endTextFrame;
  } else {
    // Not the last heading: the end of the range
    // is up to the next heading
    lastFrame = headings[i+1].parentTextFrames[0];
  }

  if (frame.nextTextFrame != lastFrame) {
    // The article is in more than one text frame.
    // Force the article into one frame
    // by making its first frame very tall
    gb[2] = gb[0]+20000;
    frame.geometricBounds = gb;
  }

  // Set the bottom of the frame to the last baseline
  gb[2] = frame.lines[-1].baseline;
  frame.geometricBounds = gb;
    
  page.resize (CoordinateSpaces.INNER_COORDINATES,
    AnchorPoint.TOP_CENTER_ANCHOR,
    ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
    [pageWidth, gb[2]+24]
  );
}

 

 

Robert at ID-Tasker
Legend
January 11, 2025

Just brainstorming... 

 

How about setting Start in Next Frame for those title style(s)? 

 

Then always setting TF insanely high? 

 

Peter Kahrel
Community Expert
Community Expert
January 11, 2025

How about setting Start in Next Frame for those title style(s)? 

 

That's already the case. See the OP's comments. And my script depends on that.

Community Expert
January 11, 2025

I already have a script that resizes a page to the selected Text Frame 

It's not very good - in my opinion - but it works for me

I'd be happy to share it and maybe it could be finesed and I could learn something too.

uniq1Author
Known Participant
January 11, 2025

Hi @Eugene Tyson Could you share it? That would be great for me.

Dave Creamer of IDEAS
Community Expert
Community Expert
January 11, 2025

Presumedly, this is not a print document. Technically, it could be printed by shrinking oversized pages to fit the paper size, but the result would basically be the same as reducing the text size to fit the content on a single page. 

If it is meant to be an online document, it sounds as if you want a website, since the HTML pages have not have a static page depth. You could use Dreamweaver, included with your Adobe CC subscription, but there are easier to use systems available for blog-type sites.

 

David Creamer: Community Expert (ACI and ACE 1995-2023)
uniq1Author
Known Participant
January 11, 2025

yes, this is not a print document. export pdf 

Dave Creamer of IDEAS
Community Expert
Community Expert
January 11, 2025

How do you expect people to print it or is it read strictly on screen?

 

David Creamer: Community Expert (ACI and ACE 1995-2023)
Robert at ID-Tasker
Legend
January 11, 2025

@uniq1

 

What are you trying to achieve? What is your end goal?

 

uniq1Author
Known Participant
January 11, 2025

In a text with paragraphs TITLE 1, TITLE 2, TITLE ... under each heading, the heading TITLE 1 and the paragraphs below it must fit on each page until the next heading, i.e. the page size must be changed. After flowing the text through the document, I want the script to place each article on one page.

Robert at ID-Tasker
Legend
January 11, 2025

@uniq1

 

Why? 

 

What will you do next - with those resized pages? 

 

 

If you work on a PC and have those texts ready - either as a separate TXT / DOC files - or in one large file - or need to get them from a database / whatever the source - and need to import into template(s) - INDD / INDT files, or Master Pages, groups / whatever - and each text into a different template, and then have them exported as a separate pages - PDF / JPEG / PNG / HTML / ePUB / whatever - and then uploaded / emailed / whatever somewhere - I have a perfect tool for you... Isn't free but it will automate the whole process 110%. 

 

Peter Kahrel
Community Expert
Community Expert
January 11, 2025

If by 'automatic' you mean 'is there an InDesign feature' then no, there isn't. But you can do a script that fits an article into one text frame, then size the page to the text frame. The only thing is that the text frame has no (practical) height limit, but the page does: 5,486 mm -- though a 55 metre tall page will probably do.

Robert at ID-Tasker
Legend
January 11, 2025

It's not possible - page can't resize automatically to the text.