# How to fetch text from pdf to further proceed with question answer based model from the same document?

To illustrate the above title.

Suppose you have a pdf document, which is basically scanned from hardcopy, now there are set of fixed questions to answer from the document itself. For an example a document contains a contract of land, now the set of fixed questions be "who is the seller?" "what is price of the asset? ", document has referred to this answers probably 2-3 times, as a human it's a simple task.

How to automate this?

• It's not so simple task for a machine, a top view of the pipeline would something like this, steps: 1) localize text 2) recognize text 3) run your further processing via Q&A it It's tough one! – Aditya Oct 6 '18 at 7:24
• I think you mean an OCR task, for example: github.com/tesseract-ocr – John Oct 7 '18 at 10:26
• Hey. @Aditya I understand, it has got some complexity. That's why I am using this forum. Please can you share your inputs at any of the process mentioned? – Arijit Das Oct 7 '18 at 11:32
• Can you please elaborate on this? – Arijit Das Oct 7 '18 at 11:37
• Follow the instructions of the installation process of tesseract-ocr. Once you installed it, use it to recognize the text from the scanned document. In the recognized text try to searching the relevant terms ("seller", "price"). Next to these terms you should find your answers. – John Oct 7 '18 at 12:24

You can use pypdf2 to extract text from pdf.

import PyPDF2

with open('sample.pdf','rb') as pdf_file, open('sample_output.txt', 'w') as text_file: