gpatankar21
Parsing pdf file
I am required to parse a resume in pdf format to extract fields like phone-number github-url linkedIn-url etc, is there any way to parse the pdf to extract this data from the pdf.
Most Liked
tme_317
I use Ghostscript to convert the PDF to a txt file then attempt to parse it.
System.cmd("gs", ["-sDEVICE=txtwrite", "-o#{txt_path}", pdf_path])
Parsing this resulting text file can be difficult if the PDFs are not of consistent format but at least you have text to work with.
NobbZ
I tend to say no, unless you have a proper FORM, but still it won’t be easy then AFAIK, but I have not used any tools that would do so, as we read and process our resumes manually at my company.
What would make it hard, is that in a PDF not necessarily a single letter of the text you read as a human has to be saved in the text. In theory, it could be drawn as a single large vector graphic.
Its rarely done due to the cost in size though, and embedding fonts and text is quite common. Still, tabular views are not saved like that necessarily.
They could be saved as a single free positioned box per cell, without any possibility to read programatically which row and column this cell belongs to, but easy recognizable as a human.
Just read the resume, or if you have a license for a good OCR software, use that. Or require resumes to be handed in in a better machine readable format.
sribe
Do you have any idea what’s actually in your larger PDF? I ask because larger might mean it’s scanned, and that it’s just images, with no text present. So yeah, do what others are asking, run command, check return code & stderr. But realize that if you want to get text from an image, you’re talking about running OCR software.
But for those that do contain text, I’d recommend Apache Tika. People are correct that there’s no requirement that text in a PDF be available in any way that you can make sense of, since it’s a list of drawing commands it could draw the characters in random order. But in real life the PDFs that you come across that are exported from word processing documents or created via print-to-pdf actually contain the text in a usable way. (Columns and tables are still tricky. But plain text is pretty easy to handle.)
peerreynders
I get an empty string in the pdf_as_text variable.
That isn’t the issue. You are using:
{pdf_as_text,_} = System.cmd(...)
You are ignoring the exit_status from System.cmd/3
You have already observed that you are getting an empty string in pdf_as_text. So use instead:
{pdf_as_text, exit_status} = System.cmd(...)
and find out what the value of exit_status is - its value may give you some hint as to why pdf_as_text is empty.
For example this lists:
0 No error.
1 Error opening a PDF file.
2 Error opening an output file.
3 Error related to PDF permissions.
99 Other error.
gpatankar21
I used pdftotext to convert the content of pdf but it does not worlb for large sized pdf’s
It works when the pdf size is about 5 kb or less. Otherwise the content is empty in pdf_as_text.
{pdf_as_text,_} = System.cmd("pdftotext", ~w[#{attrs["attachment"].filename} -], cd: "/home/gagan/aviahire-web/uploads/gagan/applicant/3/attachments/thumb")
IO.puts("++++++++")
IO.puts(pdf_as_text)
IO.puts("++++++++")







