Skip to content

[Archive] PDF Resume Authentication

Ishan Khatri edited this page Aug 23, 2019 · 1 revision

Reasoning

Since all of our resume files that were being checked were purposely limited to .pdf's, the best way to authenticate resumes was to utilize a PDf Reader and then go from there.

Impementation

With the gem file, "pdf-reader" now added, we can move forward with the authentication.

In the Model of Event Application, I added a method called "contains_name".

That method is then validated by the model when someone tries to submit their application.

Authentication Code

temp = Paperclip.io_adapters.for(resume)
        file = File.open(temp.path, "rb")

The first two lines deal with taking the Paperclip Attachment which keeps all of our resumes in a secure database, taking the root file of the Attachment and then turning it into an IO object so that the PDF reader can parse it.

 if File.extname(file) == ".pdf"

This part was a necessary addition to make sure the file was a .pdf so that the PDF Reader wouldn't crash and try to parse any other file extension type.

pdf = reader.page(1).text
            if !reader.page(1).text.include? name

The PDF Reader was a bit funky and separates the pdf through pages, and we are assuming that everyone will have their resume on one page and/or have their name on the first page.