Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'iguvium'
- require 'csv'
- pages = Iguvium.read('WL_P04.pdf')
- def pdfToCSV tables,flag
- array = tables.first.to_a
- table_column = []
- table_rows = []
- table = []
- array[3..-1].each do |row|
- row.each_with_index do |col, c|
- table_column = col.delete(',').split(' ').to_a.map(&:to_i)
- table_column.each_with_index do |v, l|
- if c == 0
- table_rows << [v]
- else
- table_rows[l] << v
- end
- end
- end
- table << [table_rows]
- table_rows = []
- end
- if flag
- CSV.open("WL_P01#Y05.csv", "w") do |csv|
- array[0..2].each do |header|
- csv << header
- end
- end
- end
- CSV.open("WL_P01#Y05.csv", "a+") do |csv|
- table.each do |data|
- data.each do |row|
- row.each do |val|
- csv << val
- end
- end
- end
- end
- end
- pdfToCSV pages[7].extract_tables!,true
- # pdfToCSV pages[18].extract_tables!,false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement