Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Autofit page size

Explorer ,
Dec 20, 2017 Dec 20, 2017

Hi everyone

I'm using Indesign since the beginning and know it very well.

I wonder if there is a trick to automatically fit the page size to its content...

Why?

Today i'm on a new project automated with EasyCatalog plugin and then i'm generating dozens of pages with different contents. Some of them are 10cm height, others are 25cm...

Thank you for your ideas ans suggestions

Regards

Miran

TOPICS
Scripting
3.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 22, 2017 Dec 22, 2017

Miran --

> i don't understand how in indesign i could adapt the page in a one click action to the content

You can't, that was the point of David Blatner's post. The nearest you get to Illustrator's functionality is a script (the point of my reply to David), and if you want Illustrator's one-click functionality, you can assign a keyboard shortcut to the script.

So you're after a way of applying the script in that link to all pages in your document, correct? That's not too hard:

if (!app.documents.le

...
Translate
Community Expert ,
Dec 21, 2017 Dec 21, 2017
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 21, 2017 Dec 21, 2017

Hi Peter

I thank you for your link. But it does't really help.

I already know this tool and use the similar tool on Illustrator to adapt my pages or workspaces (plan de travail in french) to my artwork or the contents on it.

1- i don't understand how in indesign i could adapt the page in a one click action to the content... without knowing its dimensions. This is a normal behavior in Illustrator for example, by a double click with the tool similar to the page tool (i ignore its nam in english sorry).

2- as i explained before, i have a very big file with dozens of pages and i wonder if there is a ay to fit them quickly (and not manually one by one) to their content...

Regards

Miran

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 22, 2017 Dec 22, 2017

Miran --

> i don't understand how in indesign i could adapt the page in a one click action to the content

You can't, that was the point of David Blatner's post. The nearest you get to Illustrator's functionality is a script (the point of my reply to David), and if you want Illustrator's one-click functionality, you can assign a keyboard shortcut to the script.

So you're after a way of applying the script in that link to all pages in your document, correct? That's not too hard:

if (!app.documents.length) {

  alert ('Open a document.'); exit();

}

// Set up the document

app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

app.documents[0].zeroPoint = [0,0];

app.documents[0].viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

pages = app.documents[0].pages.everyItem().getElements();

for (i = 0; i < pages.length; i++) {

  if (!pages.pageItems.length) continue;

  if (pages.pageItems.length > 1) {

    pages.groups.add (pages.pageItems.everyItem().getElements());

  }

  frame = pages.pageItems[0];

  gb = frame.geometricBounds;

  frame.move ([0, 0]);

  pages.marginPreferences.properties = {top: 0, left: 0, bottom: 0, right: 0};

  pages.resize (CoordinateSpaces.INNER_COORDINATES,

    AnchorPoint.TOP_LEFT_ANCHOR,

    ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,

    [gb[3]-gb[1], gb[2]-gb[0]]

  );

}

Peter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 22, 2017 Dec 22, 2017

Peter Hi!

Thank you very much for your very quick reply and also explanation and also this script!!!

It works very well and that's exactly what i wanted!!

1- One thing is weird, after the script action, everything on the page is grouped. I can see the line 14 doing this. But i wonder if it is possible to undo the grouping at the end of the action

2- If we would like to add some margin, i thought it was as easy as modifying the values line 19, but it doesn't work... if i put 5 in place of top: 5 for example...

Regards

Miran

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 22, 2017 Dec 22, 2017

> I wonder if it is possible to undo the grouping at the end of the action

Sure, no problem

> If we would like to add some margin . . .

Sure, no problem. Add your margins in line 15. These are in your document's measurement units.

if (!app.documents.length) {

  alert ('Open a document.'); exit();

}

app.documents[0].zeroPoint = [0,0];

app.documents[0].viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

pages = app.documents[0].pages.everyItem().getElements();

for (i = 0; i < pages.length; i++) {

  if (!pages.pageItems.length) continue;

  if (pages.pageItems.length > 1) {

    pages.groups.add (pages.pageItems.everyItem().getElements());

  }

  frame = pages.pageItems[0];

  gb = frame.geometricBounds;

  frame.move ([0, 0]);

  m = {top: 5, left: 5, bottom: 5, right: 5};

  pages.marginPreferences.properties = m;

  pages.resize (CoordinateSpaces.INNER_COORDINATES,

    AnchorPoint.TOP_LEFT_ANCHOR,

    ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,

    [gb[3] - gb[1] + m.left + m.right, gb[2] - gb[0] + m.top + m.bottom]

  );

  frame.move ([m.left, m.top]);

  try {

    frame.ungroup();

  } catch (_) {

  }

}

P.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 23, 2017 Dec 23, 2017

Hi Peter

Thank you very much again!

Very useful and very very appreciated!

Hope i could help you one day

Regards from France

Miran

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 24, 2021 Sep 24, 2021

Hi @Peter Kahrel great stuff! I tried to use this since @lemiran and I have the same problem. However, I am seeing this error. Can you please help me with this? Thank you in advance

Screen Shot 2021-09-25 at 2.06.37 AM.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2021 Sep 25, 2021

Hi Joseph,

the posted code is damaged. This has happened when the thread was moved from the old InDesign forum to this new one. Here the restored code where iterator [i] was added to pages in the for-loop:

 

if (!app.documents.length) {
  alert ('Open a document.'); exit();
}

app.documents[0].zeroPoint = [0,0];
app.documents[0].viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

pages = app.documents[0].pages.everyItem().getElements();

for (i = 0; i < pages.length; i++) {
  if (!pages[i].pageItems.length) continue;
  if (pages[i].pageItems.length > 1) {
    pages[i].groups.add (pages[i].pageItems.everyItem().getElements());
  }

  frame = pages[i].pageItems[0];
  gb = frame.geometricBounds;
  frame.move ([0, 0]);
  m = {top: 5, left: 5, bottom: 5, right: 5};
  pages[i].marginPreferences.properties = m;
  pages[i].resize (CoordinateSpaces.INNER_COORDINATES,
    AnchorPoint.TOP_LEFT_ANCHOR,
    ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
    [gb[3] - gb[1] + m.left + m.right, gb[2] - gb[0] + m.top + m.bottom]
  );

  frame.move ([m.left, m.top]);
  try {
    frame.ungroup();
  } catch (_) {
  }

}

 

NOTE 1: Make sure that your ruler units are set in Points.

NOTE 2: Also see into this thread:

 

fit paper size to content (like in Illustrator)
mycc, Sep 08, 2021
https://community.adobe.com/t5/indesign-discussions/fit-paper-size-to-content-like-in-illustrator/td...

 

Regards,
Uwe Laubender

( ACP )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 25, 2021 Sep 25, 2021

@Laubender Youre a delight. thank you so much!

 

Can I also ask how to select all active objects within a layer?

Its okay if it is a "select all" command, since all the layers are locked.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2021 Sep 25, 2021

Press Ctrl+A/Cmnd+A. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2021 Sep 25, 2021

Hi Joseph,

do you mean that you want to unlock all objects in all layers, locked or not?

Do this with this code:

app.documents[0].layers.everyItem().locked = false;
app.documents[0].pageItems.everyItem().locked = false;

 

Regards,
Uwe Laubender

( ACP )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 17, 2024 Nov 17, 2024
LATEST

Hi @Laubender , It's rare to see you out writing scripts.

Type area fits the picture not much use.


Reverse. It is more useful.
How to write picture fit type area,
And the picture fits the bleed,
And picture fit column.

 

Thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines