8 Replies Latest reply on Mar 31, 2016 12:47 AM by karthiks94217840

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

    Jackkistens

      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

        • 1. Re: I need to export all the table in "png" fomat, but continuied table also exported same as pdf..
          Laubender Adobe Community Professional & MVP

          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[n].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[x]).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

          • 3. Re: I need to export all the table in "png" fomat, but continuied table also exported same as pdf..
            karthiks94217840 Level 2

            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?


            Screen Shot 2016-03-30 at 10.25.53 AM.png


            Advance Thanks to all,


             


            • 4. Re: I need to export all the table in "png" fomat, but continuied table also exported same as pdf..
              Jackkistens Level 1

              Hi Karthick,

               

              Try this code...

               

               

               

               

              var doc = app.documents[0];

              var myFilePath = doc.filePath;

              var tableArray = doc.stories.everyItem().tables.everyItem().getElements();

              var columnCells;

               

               

              for(var txtFrm = 0; txtFrm < tableArray.length; txtFrm++)

                {

                    columnCells = tableArray[txtFrm].columns[0].cells.everyItem().getElements();

              }

               

               

               

               

              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[n].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[x]).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: 

                  // . . . 

                  

              • 5. Re: I need to export all the table in "png" fomat, but continuied table also exported same as pdf..
                Laubender Adobe Community Professional & MVP

                Hi Karthi,

                watch your selection.

                 

                In my snippet the table is the selected table.
                Not the selected text frame, that holds the table.

                 

                Uwe

                • 6. Re: I need to export all the table in "png" fomat, but continuied table also exported same as pdf..
                  karthiks94217840 Level 2

                  HI Jackkistens

                   

                  Thanks for sharing your coding. I am learning stage in the java script.

                   

                  One more help jack. Please share your full coding in the above coding.

                   

                  @The following coding:  // Your export code here:

                   

                  Advance Thanks your valuable input.

                  • 7. Re: I need to export all the table in "png" fomat, but continuied table also exported same as pdf..
                    Jackkistens Level 1

                    function exportToPNGfunction(/*pageItem*/pageItem, xxx) 

                        var appPref = app.pngExportPreferences;

                              appPref.pngQuality = PNGQualityEnum.MAXIMUM;

                              appPref.pngColorSpace = PNGColorSpaceEnum.RGB;

                              appPref.transparentBackground = false;

                              appPref.antiAlias = true;

                              appPref.exportResolution = 300;

                        var png = pageItem.exportFile(ExportFormat.PNG_FORMAT, File(new File(myFilePath+"/"+"imageName"+".png")));