InDesign table strokes - change to paths and retain text etc
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();

