XML Table with script to convert cells to graphic cells takes over 30 minutes

New Here ,
Oct 29, 2020

Copy link to clipboard


We made a script that imports an XML with a decent amount of data and a lot of tables. We sometimes have about 300-400 cells that contain pictures of varying size, so we add the row height as attributes to the cells in the XML to change the height and turn those into graphic cells : (Note the rowHeight attribute)


<OrganeTableauPhotos xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" aid:table="table" aid:trows="2" aid:tcols="3">
    <CellPicture rowHeight="43mm" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="136.06299212592387">
        <Image href="file:///C:/Job/36d2bcfe-a858-4323-89f5-ce3c550da621/e8ccd3b7-0cf2-4b08-a4c9-d5c496961a8d.jpg"></Image>
    <CellPicture rowHeight="43mm" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="136.06299212592387">
        <Image href="file:///C:/Job/36d2bcfe-a858-4323-89f5-ce3c550da621/2ca2bd71-6082-495f-8484-4f916aca76ff.jpg"></Image>
    <CellPicture rowHeight="43mm" aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="136.06299212592387">
        <Image href="file:///C:/Job/36d2bcfe-a858-4323-89f5-ce3c550da621/1b79f38b-ddff-4a1a-9c22-14c9db0899d1.jpg"></Image>
    <CellPictureLegend aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="136.06299212592387">
        <OrganeLegendePhoto>Photo 1</OrganeLegendePhoto>
    <CellPictureLegend aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="136.06299212592387">
        <OrganeLegendePhoto>Photo 2</OrganeLegendePhoto>
    <CellPictureLegend aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="136.06299212592387">
        <OrganeLegendePhoto>Photo 3</OrganeLegendePhoto>


And therefore after the import, the script goes through the cells that have this attribute and : 

  • Sets the appropriate rowHeight on the parent
  • Converts the cell to a Graphic Cell
  • Fits the graphic neatly into the cell (to keep the proportions)


var elements = activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().cells.everyItem().getElements()
for (var i = 0; i < elements.length; i++) {
    var hasRowHeight = false
    var el = elements[i]
    var val = el.associatedXMLElement.xmlAttributes.itemByName("rowHeight")

    if (!val.isValid)

    if (val.isValid) {
        hasRowHeight = true
        var size = val.value

        el.parentRow.height = size
        el.parentRow.maximumHeight = size
        el.parentRow.keepWithNextRow = true

    // Switch the cell type to Graphic
    el.convertCellType(CellTypeEnum.GRAPHIC_TYPE_CELL, true)

    if (el.allGraphics.length > 0) {
        var rect = el.rectangles.firstItem().getElements()[0]
        var graphic = el.allGraphics[0]
        activeDocument.align([graphic], AlignOptions.LEFT_EDGES, AlignDistributeBounds.KEY_OBJECT, rect)
        activeDocument.align([graphic], AlignOptions.VERTICAL_CENTERS, AlignDistributeBounds.KEY_OBJECT, rect)


The issue we're having is that sometimes the document is quite big (90+ pages, 400+ pictures) it can take 30 minutes to do this step, or even crash InDesign altogether, because resizing each graphic cell/picture individually then - we assume - reflows the whole document, and it takes about 3-5 seconds per cell, while on a small document (3 to 10 pages) it only takes about 15s


What we have noticed and are pretty sure of :


  • There is no way to set the row height from the XML, it needs to be done from a script
  • Elements like the Image in our example XML cannot be mapped to Object Styles in the Tags-to-styles mapping, so we also need to apply those align/fit options through the script
  • Even if in our InDesign Template we have graphic cells, once we import the tables, the cells go back to being text cells, so we need to convert them back to graphic cells from the script


Does anyone have an idea on how to improve this workflow ?


Import and export, Performance, Scripting







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

Have something to add?

Join the conversation