Skip navigation
Currently Being Moderated

[JS][CS4] - Transformation Matrix and Tables

Nov 23, 2011 1:32 PM

Tags: #cs4 #javascript #indesign #scripting #cals_tables



I'm trying to loop through all pages of a document and scale down each entire page. Right now I'm grouping the items and trying to use a transformation matrix on the entire group. It works great except for the table that is just one part of the grouped object. The table seems to resize twice becuase it is extremely smaller than all other page items which seem to scale together correctly. Here is the code:


var doc = app.activeDocument;


for (i=0, i<doc.pages.length-1; i++){
     var myGroup = doc.pages[i].pageItems[0];
     var myScaleMatrix = app.transformMatrices.add({horizontalScaleFactor: .8, verticalScaleFactor: .8});
     myGroup.transform(CoordinateSpaces.pasteboardCoordinates, AnchorPoint.CenterAnchor, myScaleMatrix);

Is there a better way to transform a table?  If I do not loop and simple use:


var myGroup = doc.pages[0].pageItems[0];


to execute the transformation it works how I expect it to where the entire group scales down. Why would the loop introduce a problem?


Is this something I could acheive with adjustLayout?  I would want to scale down to new margins; however I don't want the text to reflow. This is why I opted to use the transformation Matrix.


Any help is greatly appreciated.




  • Currently Being Moderated
    Nov 23, 2011 2:03 PM   in reply to booyajamo

    Is that a table inline in running text, or in a frame of its own, or an anchored object perhaps?

    Mark as:
  • Currently Being Moderated
    Nov 23, 2011 2:35 PM   in reply to booyajamo

    lindsaygensinger wrote:


    It's in a frame of it's own.


    Well then you got yourself a weird side-effect Your script only applies the scaling to 'pageItem[0]', any old item that would be the very first on that page. It leaves all others unchanged (or so it should, but then that could be the weird side effect).


    By the way, your script didn't run straight away, there were a couple of typo's. Please make sure to copy the exact script that works for you (or in this case, that doesn't work).


    By the way #2: do you deliberately scale down all of your pages except the last one?


    Anyway, a solution that worked for me is to grab all of the page items into a single group and then apply your code:


    doc = app.activeDocument;
    for (i=0; i<doc.pages.length-1; i++){
         var myGroup = doc.pages[i].pageItems.everyItem();
         var myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor: .8, verticalScaleFactor: .8});
         myGroup.transform(CoordinateSpaces.pasteboardCoordinates, AnchorPoint.CENTER_ANCHOR, myScaleMatrix);


    (With typos fixed so I know it works. Mind you, it still doesn't scale down the very last page.)

    Mark as:
  • Currently Being Moderated
    Nov 23, 2011 2:39 PM   in reply to [Jongware]

    I now notice there is a slight re-run in the text of my test file. Some things will not stay the same when scaling down, apparently.


    Perhaps a better way would be to export to PDF and scale that down into a new document.

    Mark as:
  • Currently Being Moderated
    Nov 23, 2011 2:56 PM   in reply to booyajamo

    lindsaygensinger wrote:


    Why would it work correctly if I don't loop and I directly tell it to scale the first pageItem on the first page?  Is the loop, going through the page a second time or something and reducing the table a second time?


    Theoretically, no. I got a different result, but it may just be a side effect of the actual way your document is designed.



    lindsaygensinger wrote:

    I don't fully understand how the adjustLayout works but might that be a solution to look into?  If I adjust the margins down or up will I be able to scale the contents to the margins?


    No, Adjust Layout doesn't work that way. First of all, it only works correctly for page items that fill the entire margins of your document. Objects that touch a page margin get moved but not scaled down.

    Second, and more important, it doesn't scale your text down inside the frames. It's designed to allow for margin changes, and as such it will radically move your text around.


    If you have a complete finished document and just need to scale to another page size, go with the PDF route. Alternatively -- I don't have experience with this -- you can place your entire original InDesign document into a new correctly sized one.

    I think you can use Scott Zanelli's MultiPageImporter to do either.


    (Gosh whats up with Jive today!? I can't even reliably insert a hyperlink, I have to double-check in the raw HTML view if it actually worx!)

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points