Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
12444 มุมมอง

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.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ส.ค. 25
209
3
ส.ค. 25
1567
1
ก.ค. 25
602
0
ส.ค. 25
499
1
มิ.ย. 25
925