跳至內容
選單
此問題已被標幟
2 回覆
12448 瀏覽次數

The scenario is this,

I have a class with binary field,

file_to_import = fields.Binary('File')

file_to_import_fname = fields.Char('Filename')

The file to be submitted to this field is in predefine format and if of type PDF.

I have a button next to the binary field in view, Import. The related action uses tabula, parse through file and retrieve table contents in it and create records.

How do I pass the base64 encoded string to Tabula. The line to read PDF contents in tabula is,

df = tabula.read_pdf(file_to_import, output_format="json", pages="all")

頭像
捨棄
作者 最佳答案

I can read the contents of the file with this technique.

pdf_file = open('/tmp/pdffile.pdf','w')
pdf_file.write((base64.b64decode(obj.file_to_import)))
pdf_file.close()

df = tabula.read_pdf("/tmp/pdffile.pdf", output_format="json", pages="all")

頭像
捨棄
最佳答案

That's a very good trick. I will try that on. Thanks.

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
8月 25
212
3
8月 25
1571
1
7月 25
605
0
8月 25
500
1
6月 25
929