0

Sometimes we have big images in word file and after importing this word file inside InDesign, the image goes inside the overflow text and the text flow stops at this point.

We couldn't resize these images or can't get hold of this image for applying any scripting logic.

Basically, I will search for figure parastyle, then check for rectangles inside the para, and do resize logic. Sample jsx code here:

app.findTextPreferences.appliedParagraphStyle= 'figure';
var founds = app.findText();

// find 92% text width area
var pageWidth = this.props.textAreaWidth * 92 /100;
for(var i=0, len=founds.length; i<len; i++){
    // find the rectangles inside the para
    var rect = founds[i].rectangles;
    if(rect.length == 0) continue;
    var vb = rect[0].visibleBounds;
    var imgWidth = vb[3] - vb[1];
    // image resize logic
    if(imgWidth > pageWidth){
        vb[3] = pageWidth;
        rect[0].visibleBounds = vb;
        rect[0].fit(FitOptions.PROPORTIONALLY);
        rect[0].fit(FitOptions.FRAME_TO_CONTENT);
    }

How to apply some logic to the images which are in the overflow text? how to resize the image which is in overflow text?

We can just import the below word file into any InDesign template

Sample word file

Shiv
  • 1,211
  • 4
  • 14
  • 24

1 Answers1

0

You could iterate through all the graphics and resize the big ones.

var images = app.activeDocument.allGraphics;

var max   = {};
    max.w = 100; // max width
    max.h = 100; // max height

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

    var gb     = images[i].geometricBounds;
    var size   = {};
        size.w = -gb[1] + gb[3];
        size.h = -gb[0] + gb[2];

    if (size.w > max.w || size.h > max.h) {
        var scale = (size.w > size.h) ? max.w/size.w : max.h/size.h;
        images[i].horizontalScale *= scale;
        images[i].verticalScale   *= scale;
        images[i].parent.fit(FitOptions.FRAME_TO_CONTENT);
    }
}
Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23