Thank you for all comments!
- group the three elements
- get the geometric bounds of the group
- resize the page to the dimensions of the groups bounds
- make sure the group is exactly on the page
How can I do it by script? On page I can have many elements (textboxes, images, lines, circles, other geometrical stuff), not only 3 - some also grouped, some not. And I have to "cut" the page from all the sides to match exactly the content.
This script follows the recipe:
doc = app.documents;
g = doc.pages.groups.add (doc.pages.allPageItems);
bounds = g.geometricBounds;
doc.documentPreferences.pageHeight = bounds - bounds;
doc.documentPreferences.pageWidth = bounds - bounds;