title: Convert PDF to CSV using java
body: <p>I have tried most of the things on stack overflow and outside</p>
  
  <p><strong>Problem</strong> :
  I have a pdf with contents and tables .
  I need to parse tables and content as well.</p>
  
  <p><strong>Apis :</strong>
  <a href="https://github.com/tabulapdf/tabula-java" rel="noreferrer">https://github.com/tabulapdf/tabula-java</a>
  I am using <code>tabula-java</code> which ignores some contents and contents inside table cells are not seporated proper way.</p>
  
  <p>MY PDF IS having content like this</p>
  
  <pre><code> DATE :1/1/2018         ABCD                   SCODE:FFFT
                         --ACCEPTED--
      USER:ADMIN         BATCH:RR               EEE
      CON BATCH
      =======================================================================
      MAIN SNO SUB  VALUE DIS %
      R    12   rr1 0125  24.5
              SLNO  DESC  QTY  TOTAL  CODE   FREE
              1     ABD   12   90     BBNEW  -NILL-
              2     XDF   45   55     GHT55  MRP
              3     QWE   08   77     CAT    -NILL-
      =======================================================================
      MAIN SNO SUB  VALUE DIS %
      QW    14   rr2 0122  24.5
              SLNO  DESC  QTY  TOTAL  CODE   FREE
              1     ABD   12   90     BBNEW  -NILL-
              2     XDF   45   55     GHT55  MRP
              3     QWE   08   77     CAT    -NILL-
  </code></pre>
  
  <p>Tabula code to convert :</p>
  
  <pre><code>public static void toCsv() throws ParseException {
          String commandLineOptions[] = { "-p", "1", "-o", "$csv", };
          CommandLineParser parser = new DefaultParser();
          try {
              CommandLine line = parser.parse(TabulaUtil.buildOptions(), commandLineOptions);
              new TabulaUtil(System.out, line).extractFileInto(
                      new File("/home/sample/firstPage.pdf"),
                      new File("/home/sample/onePage.csv"));
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>tabula even supports command line interface </p>
  
  <pre><code>java -jar TabulaJar/tabula-1.0.2-jar-with-dependencies.jar -p all  -o  $csv -b Pdfs
  </code></pre>
  
  <p>I have tried using <code>-c,--columns &lt;COLUMNS&gt;</code> of tabula 
  which is takes cells by X coordinates of column boundaries</p>
  
  <p>But the problem is my pdfs content is dynamic. i.e table sizes are changed.</p>
  
  <p>These links in stack overflow and many more dint worked for me.</p>
  
  <p><a href="https://stackoverflow.com/questions/49560486/how-to-convert-pdf-to-csv-with-tabula-py">How to convert PDF to CSV with tabula-py?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/30310416/how-to-extract-table-data-from-pdf-as-csv-from-the-command-line">How to extract table data from PDF as CSV from the command line?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/49314190/convert-pdf-to-excel-in-java">Convert PDF to Excel in Java</a></p>
  
  <p><a href="https://stackoverflow.com/questions/7581995/how-to-convert-a-pdf-file-into-csv-file">How to convert a pdf file into CSV file?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/11792465/itext-converting-pdf-to-csv">itext Converting PDF to csv</a></p>
  
  <p><a href="https://stackoverflow.com/questions/38864370/parse-pdf-table-and-display-it-as-csvjava">Parse PDF table and display it as CSV(Java)</a></p>
  
  <p>I have used pdf box which gives text which is unformatted where i cant read the table content properly.</p>
  
  <p>Is posible to convert pdf with tables to <strong>csv/excel</strong> using java without loosing content and formatting.</p>
  
  <p><strong>I dont want to use paid libraries .</strong></p>