Skip to main content
Jackkisten
Inspiring
March 21, 2016
Answered

I need to export all the table in "png" fomat, but continuied table also exported same as pdf..

  • March 21, 2016
  • 1 reply
  • 1018 views

Dear All,

i need to export all the table as "png" image format.

in case any continued table is there, example table continued 2 page; i need the same page by page (2 images) required.

Please suggest, how to handle these cases in javascript.

Regards,

S.Suresh

This topic has been closed for replies.
Correct answer Jackkisten

Thank Laubender and uwe!!

1 reply

Community Expert
March 21, 2016

Hi,

for that I'd do a series of duplicate actions for every text frame the table is in and strip off additional text, that is not part of the table. Then you can export the duplicates of the text frames as PNG. Perhaps doing a fit on the text frames as well.

There are already a lot of discussions here in the forum how to determine what cell (or what row) is part of what text frame. One could use an insertionPoint inside a text cell and ask for parentTextFrames[0]. So iterate through all the cells of one column to get the needed text frames and then duplicate them.

To get the frames you could use the snippet below, if all cells are of type text (InDesign CC 2015) or if using with earlier versions of InDesign you can be sure, that cells "nearly always * " have one insertionPoint to access the parentTextFrame collection. At least this snippet will get you started.

* Make sure that there is no overset in cells (or the table itself is not part of a overset story) and that empty cells can carry at least one character without going to overset.

var doc = app.documents[0];

// Starting with a selected table

var table = app.selection[0];

var columnCells = table.columns[0].cells.everyItem().getElements();

// Preparing an array:

var textFrameIDsArray = [];

var columnCellsLength = columnCells.length;

var x;

for(var n=0;n<columnCellsLength;n++)

{

    // The id of the parent text frame viewed from a single cell.

    // Make sure, that there IS ACTUALLY AT LEAST ONE insertion point you can work with!

    var id = columnCells.insertionPoints[0].parentTextFrames[0].id;

  

    // Feeding the array with unique entries for every id needed:

    textFrameIDsArray[id.toString()] = id;

}

for(x in textFrameIDsArray)

{

    var dup = doc.pageItems.itemByID(textFrameIDsArray).duplicate();

  

    fitAndReduceWhenNeeded(dup);

    exportToPNGfunction(dup);

  

    // Cleaning up after export:

    dup.remove();

  

};

// Dummy function

function exportToPNGfunction(/*pageItem*/pageItem)

{

    // Do all neccessary controls here for exporting to PNG.

    // Mainly naming the PNG file. All other controls like resolution,

    // bit-depth, transparency etc. could be done elsewhere,

    // if the they are uniform for all PNGs that should be exported

  

    // Your export code here:

    // . . .

}

// Dummy function

function fitAndReduceWhenNeeded(/*pageItem*/pageItem)

{

    // Strip out text before or after the table in the text frame here.

    // Then fit the text frame to its contents, the table,

    // to minimize the area of the PNG to export.

  

    // Your code here:

    // . . .

  

}

And there is plenty of code in this forum how you can access all level one-tables (not nested tables) in your document.
One example:

app.documents[0].stories.everyItem().tables.everyItem().getElements();

Uwe

Jackkisten
JackkistenAuthorCorrect answer
Inspiring
March 30, 2016

Thank Laubender and uwe!!

karthikS
Inspiring
March 30, 2016

HI Laubender & uwe!!


First: Thanks for sharing your above java coding.


I have run for your script, but i got the some error comment (attached screenshot for your reference). Please suggest friends, what can i do?



Advance Thanks to all,