0

I selected the area using Tabula as below in the app and created a template. The out put in web works. But when I do it via code below I get an error "The output file is empty".

Area selection

enter image description here

Code

import tabula
    
    df = tabula.io.read_pdf_with_template(input_path="C:/Users/dnalaka/Desktop/DEF.2400-20221117.pdf",
    template_path="C:/Users/dnalaka/Desktop/DEF.json",
    format="csv",
    output_path= "C:/Users/dnalaka/Desktop/DEF.2400-20221117.csv",stream=True)

When I check the CSV file it has below data in it.

[{"extraction_method":"stream","top":107.867,"left":27.011,"width":185.21499633789062,"height":44.198997497558594,"right":212.226,"bottom":152.066,"data":[[{"top":113.68,"left":29.48,"width":45.7966423034668,"height":5.309999942779541,"text":"Net. Liq."},{"top":0.0,"left":0.0,"width":0.0,"height":0.0,"text":""},{"top":113.68,"left":150.46,"width":53.329994201660156,"height":5.309999942779541,"text":"39,749,795"}],[{"top":127.63,"left":29.48,"width":37.35663986206055,"height":5.309999942779541,"text":"Haircut"},{"top":0.0,"left":0.0,"width":0.0,"height":0.0,"text":""},{"top":127.63,"left":150.47,"width":57.230003356933594,"height":5.309999942779541,"text":"20,659,245-"}],[{"top":141.57,"left":29.48,"width":33.08664321899414,"height":5.309999942779541,"text":"Excess"},{"top":0.0,"left":0.0,"width":0.0,"height":0.0,"text":""},{"top":141.57,"left":150.47,"width":53.329994201660156,"height":5.309999942779541,"text":"19,090,549"}]]}]

My template content

[{"page":1,"extraction_method":"guess","x1":27.010627264785583,"x2":212.22643048744183,"y1":107.86715812683106,"y2":152.06638389587403,"width":185.21580322265626,"height":44.19922576904297}]

How can I get the data saved into a CSV ?

Don Nalaka
  • 129
  • 1
  • 11

1 Answers1

0

I notice the out put format defining really doesn't work in the function. However, it does out put the data in JSON format. As we have it in a data frame we can simply save it to a csv file.

df[0].to_csv(csv_path)
Don Nalaka
  • 129
  • 1
  • 11