如何从Fitz字典中提取数据

时间:2019-05-18 10:39:43

标签: python pdf

我使用Fitz(一个python包)从pdf文件中读取表格,该文件是使用以下代码提取的:

import fitz
import numpy as np
import pandas as pd

doc = fitz.open('book.pdf')
target = doc.loadPage(31)
text_dict = target.getText('dict')
blocks = text_dict['blocks']

摘录如下:

{'type': 0, 'lines': [{'wmode': 0, 'dir': (1.0, 0.0), 'spans': [{'font':'Arial', 'size': 7.019999980926514, 'flags': 0, 'text': ' '}], 'bbox': (42.540000915527344, 12.844992637634277, 44.49156188964844, 20.68764877319336)}], 'bbox': (42.540000915527344, 12.844992637634277, 44.49156188964844, 20.68764877319336)} -------------------------------------- {'type': 0, 'lines': [{'wmode': 0, 'dir': (1.0, 0.0), 'spans': [{'font': 'Arial', 'size': 9.0, 'flags': 0, 'text': ' '}], 'bbox': (260.82000732421875, 720.37255859375, 263.322021484375, 730.42724609375)}, {'wmode': 0, 'dir': (1.0, 0.0), 'spans': [{'font': 'Arial', 'size': 9.0, 'flags': 0, 'text': ' '}], 'bbox': (42.540313720703125, 730.7522583007812, 45.04231262207031, 740.8069458007812)}, {'wmode': 0, 'dir': (1.0, 0.0), 'spans': [{'font': 'Arial', 'size': 9.0, 'flags': 0, 'text': ' '}], 'bbox': (260.82000732421875, 741.072509765625, 263.322021484375, 751.127197265625)}], 'bbox': (42.540313720703125, 720.37255859375, 263.322021484375, 751.127197265625)}

如何将此字典转换为具有原始数据的csv文件格式。

0 个答案:

没有答案