Skip to content

Instantly share code, notes, and snippets.

@jeremybmerrill
Created January 18, 2014 05:12
Show Gist options
  • Save jeremybmerrill/8486499 to your computer and use it in GitHub Desktop.
Save jeremybmerrill/8486499 to your computer and use it in GitHub Desktop.
A snippet to extract spreadsheet data from a PDF using Tabula's tabula-extractor
require 'tabula'
pdf_file_path = "czechmaybe.pdf"
outfilename = "czechmaybe.csv"
out = open(outfilename, 'w')
extractor = Tabula::Extraction::ObjectExtractor.new(pdf_file_path, [5] ) #:all ) # 1..2643
extractor.extract.each do |pdf_page|
pdf_page.spreadsheets.each do |spreadsheet|
out << spreadsheet.to_csv
out << "\n\n"
end
end
out.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment