Class TableUtils


  • public class TableUtils
    extends Object
    This class provides a set of convenience methods related to working with Tables.
    Version:
    ©2004-2024 Snowtide
    • Method Detail

      • convertToCSV

        public static String convertToCSV​(Table table,
                                          char delim,
                                          String linebreak)
                                   throws IOException
        Returns a CSV-formatted String based on the contents of the given Table, using the specified character as a cell delimiter and the specified String as a linebreak sequence.
        Throws:
        IOException - if an error occurs generating the CSV conversion
      • tableToStrings

        public static String[][] tableToStrings​(Table table)
                                         throws IOException
        Returns a two-dimensional array of Strings carrying the contents of the given Table in row/cell order. For example, this:
             String[][] tableText = TableUtils.tableToStrings(pdfxstreamTable);
             String cell = tableText[0][2];
         
        Obtains the textual content of the pdfxstreamTable Table, and singles out the text of the third cell in the first row of that table.
        Throws:
        IOException - if an error occurs extracting any of the table's text
      • convertTablesToCSV

        public static String[] convertTablesToCSV​(Page p,
                                                  char delim,
                                                  String linebreak)
                                           throws IOException
        Returns an array of CSV-formatted Strings, one for each Table found in the given page, using the specified character as a cell delimiter and the specified String as a linebreak sequence. This is simply a shortcut to applying convertToCSV(Table, char, String) to each Table in the given Page manually.
        Throws:
        IOException - if an error occurs generating the CSV conversion
      • getAllTables

        public static List<Table> getAllTables​(Page p)
        Returns a List of Table instances that are available in the given Page.