gpatankar21

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

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

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

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

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

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("++++++++")

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement