Skip to main content
Community Expert
November 5, 2024
Question

InDesign table strokes - change to paths and retain text etc

  • November 5, 2024
  • 3 replies
  • 681 views

I'm trying to bring tables, long tables, short tables, tables that span columns and more exciting InDesign tables ----- to bring them into Illustrator (!!!don't ask!!!) 

 

Basically - exporting to EPS / PDF etc. breaks the table strokes into parts - and also breaks up the text and also some text is converting to outline opening in Illustrator. 

 

My idea was to convert the indesign table to a drawn table where the table cells are objects, like paths.

 

But my scripting knowledge only brings me so far. 

 

What I need to do is convert any table, whether the cells are merged or not - span columns etc. 

That the table becomes strokes - continunous lines and not jointed (cos might need to resize a column or row)

 

So far I've got this - but it's very clean - basically make a table in indesign size the text frame to the table and run the script.

 

But it breaks if the cells are merged. 

 

I just ned for the table to be generated as strokes 

It kinda works

 

If anyone would be so kind to help me 

 

Thanks 

function convertTableToOutline() {
    // Ensure there's an active selection
    if (app.selection.length !== 1 || !(app.selection[0] instanceof Table)) {
        alert("Please select a table.");
        return;
    }

    var doc = app.activeDocument;
    var table = app.selection[0]; // Target the selected table
    var tableBounds = table.parent.geometricBounds; // Get the bounds of the parent text frame

    var topOffset = tableBounds[0];
    var leftOffset = tableBounds[1];

    // Loop through each cell to create outline paths for each unique border
    for (var row = 0; row < table.rows.length; row++) {
        for (var col = 0; col < table.columns.length; col++) {
            var cell = table.rows[row].cells[col];
            
            // Calculate cell bounds relative to table bounds
            var cellTop = topOffset + cell.parentRow.index * cell.height;
            var cellBottom = cellTop + cell.height;
            var cellLeft = leftOffset + cell.parentColumn.index * cell.width;
            var cellRight = cellLeft + cell.width;

            // Draw the top border if it's the first row
            if (row == 0) {
                var topLine = doc.graphicLines.add();
                topLine.paths[0].pathPoints[0].anchor = [cellLeft, cellTop];
                topLine.paths[0].pathPoints[1].anchor = [cellRight, cellTop];
                topLine.strokeColor = cell.topEdgeStrokeColor;
                topLine.strokeWeight = cell.topEdgeStrokeWeight;
            }

            // Draw the bottom border if it's the last row
            if (row == table.rows.length - 1) {
                var bottomLine = doc.graphicLines.add();
                bottomLine.paths[0].pathPoints[0].anchor = [cellLeft, cellBottom];
                bottomLine.paths[0].pathPoints[1].anchor = [cellRight, cellBottom];
                bottomLine.strokeColor = cell.bottomEdgeStrokeColor;
                bottomLine.strokeWeight = cell.bottomEdgeStrokeWeight;
            }

            // Draw the left border if it's the first column
            if (col == 0) {
                var leftLine = doc.graphicLines.add();
                leftLine.paths[0].pathPoints[0].anchor = [cellLeft, cellTop];
                leftLine.paths[0].pathPoints[1].anchor = [cellLeft, cellBottom];
                leftLine.strokeColor = cell.leftEdgeStrokeColor;
                leftLine.strokeWeight = cell.leftEdgeStrokeWeight;
            }

            // Draw the right border if it's the last column
            if (col == table.columns.length - 1) {
                var rightLine = doc.graphicLines.add();
                rightLine.paths[0].pathPoints[0].anchor = [cellRight, cellTop];
                rightLine.paths[0].pathPoints[1].anchor = [cellRight, cellBottom];
                rightLine.strokeColor = cell.rightEdgeStrokeColor;
                rightLine.strokeWeight = cell.rightEdgeStrokeWeight;
            }
        }
    }

    alert("Table converted to outlines with continuous borders!");
}

convertTableToOutline();

 

This topic has been closed for replies.

3 replies

Community Expert
November 12, 2024

Just coming back to this if anyone has a good idea to get a table to *edit* Illustrator from* Indesign as clean as possible?

@Peter Kahrel @Robert at ID-Tasker @Joel Cherney @m1b 

Just tagging a few sorry if it's in appropriate but would like some help from anyone with as much success in scripting as possible.

 

Problems with PDF from Indesign
Text broken up - lines broken up 

 

Same with EPS or any other format

 

Copy and paste is hit and miss

 

Need large tables, small tables, spanning columns, merged/unmerged cells - basically any scenario you can think of.

 

Then have a really clean table layout in Illustrator without any broken lines/text etc. 

 

I tried the scripting route myself but I'm completely lost on how to proceed.
Or if I should even proceed.

Robert at ID-Tasker
Legend
November 12, 2024

How about just creating TextFrames for each Cell? 

 

You won't get lines spanning multiple rows / columns - but maybe it won't be such a big deal breaker? 

 

Community Expert
November 12, 2024

Will the lines translate to illustrator?

Robert at ID-Tasker
Legend
November 5, 2024

You need to check columnSpan and rowSpan - if it's >1 - then you need to add width / height of each "additional" column / row.

 

On the other hand - you are adding cell's width / height so it should work - even for merged cells... 

Community Expert
November 5, 2024

Yeh I can't get it to work - I can get a normal table to create strokes.

But they're all individual and would prefer if it was a singular line to separate columns/rows so it's easier to adjust when brought into illustrator.

doing tables in illustrator is a pain - idea is to do it in InDesign then import to Illustrator - but it's very unreliable on table strokes and text splitting etc. 

 

 

Robert at ID-Tasker
Legend
November 5, 2024

So you want to have one line through multiple cells - not for each cell? 

 

Robert at ID-Tasker
Legend
November 5, 2024

Can you post a screenshot showing what's wrong when cells are merged? 

 

Community Expert
November 5, 2024

Sorry I think i posted the incorrect version of the script

Here's the screenshot of the error when cells are merged

 

 

This is the one that almost works - apologies again

function convertTableToOutline() {
    // Ensure there's an active selection
    if (app.selection.length !== 1 || !(app.selection[0] instanceof Table)) {
        alert("Please select a table.");
        return;
    }

    var doc = app.activeDocument;
    var table = app.selection[0]; // Target the selected table
    var tableBounds = table.parent.geometricBounds; // Get the bounds of the parent text frame

    var topOffset = tableBounds[0];
    var leftOffset = tableBounds[1];

    // Loop through each cell to create outline paths for each border
    for (var row = 0; row < table.rows.length; row++) {
        for (var col = 0; col < table.columns.length; col++) {
            var cell = table.rows[row].cells[col];
            
            // Calculate cell bounds relative to table bounds
            var cellTop = topOffset + cell.parentRow.index * cell.height;
            var cellBottom = cellTop + cell.height;
            var cellLeft = leftOffset + cell.parentColumn.index * cell.width;
            var cellRight = cellLeft + cell.width;

            // Create lines for each border of the cell using paths
            var topLine = doc.graphicLines.add();
            topLine.paths[0].pathPoints[0].anchor = [cellLeft, cellTop];
            topLine.paths[0].pathPoints[1].anchor = [cellRight, cellTop];
            topLine.strokeColor = cell.topEdgeStrokeColor;
            topLine.strokeWeight = cell.topEdgeStrokeWeight;

            var rightLine = doc.graphicLines.add();
            rightLine.paths[0].pathPoints[0].anchor = [cellRight, cellTop];
            rightLine.paths[0].pathPoints[1].anchor = [cellRight, cellBottom];
            rightLine.strokeColor = cell.rightEdgeStrokeColor;
            rightLine.strokeWeight = cell.rightEdgeStrokeWeight;

            var bottomLine = doc.graphicLines.add();
            bottomLine.paths[0].pathPoints[0].anchor = [cellLeft, cellBottom];
            bottomLine.paths[0].pathPoints[1].anchor = [cellRight, cellBottom];
            bottomLine.strokeColor = cell.bottomEdgeStrokeColor;
            bottomLine.strokeWeight = cell.bottomEdgeStrokeWeight;

            var leftLine = doc.graphicLines.add();
            leftLine.paths[0].pathPoints[0].anchor = [cellLeft, cellTop];
            leftLine.paths[0].pathPoints[1].anchor = [cellLeft, cellBottom];
            leftLine.strokeColor = cell.leftEdgeStrokeColor;
            leftLine.strokeWeight = cell.leftEdgeStrokeWeight;
        }
    }

    alert("Table converted to outlines successfully!");
}

convertTableToOutline();

 

 

Robert at ID-Tasker
Legend
November 5, 2024

I think the problem is with parentRow.index for merged cells?