Reading pdf file in Document

I am trying to parse a pdf file uploaded by user .


python code

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
import PyPDF2
class Resume(Document):
	pass

@frappe.whitelist(allow_guest=True)
def get_document_type(doc):
	pdfReader = PyPDF2.PdfFileReader(open(doc, 'rb'))
	pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
	pages = pdfReader.numPages
	pageObj = pdfReader.getPage(0)
	return pageObj.extractText()

js code

	process:function(frm){
		frappe.call({
			method: "anther.anther.doctype.resume.resume.get_document_type",
			args: {
				'doc': frm.doc.upload_resume
			},
			callback: function (r) {
				console.log(r)
			}
		})
	}

getting error

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 61, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 21, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 56, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1030, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/anther/anther/anther/doctype/resume/resume.py", line 15, in get_document_type
    pdfReader = PyPDF2.PdfFileReader(open(doc, 'rb'))
IOError: [Errno 2] No such file or directory: u'/files/Aditya_Resume.pdf'

Where am i going wrong ?

2 Likes

You need to pass the full path of the document. See frappe.get_site_path

Hi @Aniket_Shinde1

I assume from your question that you have implemented resume parsing into the HR/Recruitment module. Has this proved successful?

Same question. Do anyone have answer for this??

@Aniket_Shinde1