cgraham
Hi!
What is currently the best library/method for parsing text and tabular data out of PDF files in Elixir or Erlang?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #elixirconf-us
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
asianfilm
I don’t think there is one. But would love to be proved wrong. There are a couple of PDF parsers written in Elm, one with an interesting UI. You’d think that Elixir would be a more natural choice given its pattern matching. I have thought of converting one to Elixir, but it would likely only handle text and not tables.
kip
I had a very similar idea. Until I started reading the PDF specification …
(Even after buying two technical books on it)
kokolegorille
There is one in Python…
slouchpie
About 1 year ago, I attempted a “side-project” for a guy who I met at a laptop repair place. It was a site with some simple functionality but he wanted PDF parsing. I gave up after about 4 weekends.
I tried using the python
pdfreaderlibrary but found it extremely brittle. I actually am reading the email chain from Aug 2023 about it and I explained to the guy that unpredictable spacing and layouts made a catch-all solution almost impossible (for me, at least, I’m sure some AI wizards born and raised in soundproof bunkers deep under Silicon Valley could do it).Anyway, so I tried another approach which actually works very well, but only if the PDF format does not change. I wrote something that worked for all the test data presented but the next batch of data was wildly different (different table headings, different number of columns, different data types, random annotations and notes in strange places).
This 2nd approach used a Java jar called
tabula. I got it from here https://github.com/tabulapdf/tabula-java/releases/download/v1.0.5/tabula-1.0.5-jar-with-dependencies.jar but check around, maybe there are later releases. It worked super well (until the inputs started changing like crazy).Anyway, if you want my honest opinion - do it yourself if you have strong control over the input pdfs and if there is a tolerance for mistakes. Otherwise, use an established pdf parsing service.
With all that said, here is some Elixir code I wrote (hastily) about a year ago to parse a specific pdf. I am just copying and pasting it wholesale so please don’t judge it too harshly. Maybe you can scavenge it for parts.
Good luck.
bdarla
I also went for a Java based solution, i.e. tika-server.
Then, I use e.g. HTTPoison to send the PDF content to
http://localhost:9998/tikaand I parse the result using Floki, e.g. metadata or content.It is an easy solution that works, though I cannot argue that it is the optimal solution.
tme_317
I currently use ‘pdftotext’ currently distributed in poppler to extract the text out of PDFs called by ‘System.cmd’.
After that it’s easy to parse the text file with standard Elixir code. Previously I used Ghostscript to extract text but I find pdftotext’s -layout option provides more consistent formatting of the text output making it easier to parse.
carlgleisner
Excellent question
I’ve looked into this and found three main ways:
pdf2txt.py1. Python libraries
There is
pdfreaderas mentioned by @kokolegorille. Another one ispdf2txt.pyfrom thepdfminer.sixpackage, which I use myself for some simpler use cases.One thing that limited me with this was that a recurring element in my documents (a vector and text stamp) didn’t show up with the correct line ordering in the extracted plaintext. That could be manageable for one kind of element – but quickly gets utterly unmanageable. So: it depends.
2. “Document AI” models
This is a really cool blog post on Huggingface setting out how one can use machine learning utilising not only textual information, but also positional information and scanned documents.
There is a neat table describing the licenses of the models. What’s really appealing to me is the possibility to run inference on your own.
But last time I checked I think that the cost of getting started seemed too high for me. Also, I don’t think that it’s as easy as Bumblebee 1-2-3 quite yet. Which brings me to what I went for
3. Third-party service
Since we’re a Microsoft shop I looked into Azure Document Intelligence and… yeah, it’s really nice actually.
For our use-case it’s been great. To start with, we’re a Microsoft shop as I mentioned. But primarily, it was easy to get started with the web interface giving you point and click labelling for subsequent training. Finally, we don’t have to scale massively. I guess inference could get prohibitively expensive if you do.
The coolest option? Gosh no. I wish I was the European version of Sean Moriarty, but I’m certainly not. Azure Document Intelligence allowed me to become terribly productive and cost has thus far been way below what would be acceptable.
Best of luck with your endeavor!
PS. If even @kip balks at the idea of writing a PDF parser, then I’ll be running the other way immediately.
slouchpie
Yes!
Also yes to the 3rd-party service.
akoutmos
For tabular data I have had really good luck using Tabula (GitHub - tabulapdf/tabula-java: Extract tables from PDF files · GitHub). Usage is pretty simple too and you’ll get the contents of tables in the PDF back as a CSV on STDOUT:
The only downside is I needed to add Java to my docker image…but such is life.
xavriley
For image based PDFs, GitHub - datalab-to/surya: OCR, layout analysis, reading order, table recognition in 90+ languages · GitHub is excellent. It’s recently released, open source and competes with the major cloud services for accuracy. It has some restrictions on commercial use above $5M USD gross p/a (a nice problem to have) but otherwise is free to use. Running a page through surya and passing the bounding box data (as json) into ChatGPT seems to give good comprehension on tabluar data too. Combining it with a structured output solution like Instructor or Outlines would probably yield good results.
I’ve been planning to use a similar setup (Elixir + surya) for some open data projects but haven’t got round to it yet. Please let us know how you get on with it.
For text based PDFs I agree with the suggestion of using Tika, although it’s been a few years since I worked with it so take that with a pinch of salt.