A Rust PDF to Text GUI

A few months ago I started working on a PythonOCR python version of this. However, it was slow and more importantly, it was a pain to install on other machines. My primary motivation for writing this software is because I am in graduate school, and we often have long PDF files that we need to read. My eyes aren't what they used to be and sometimes it's nice to be able to change or bold the font, along with the usual benefit of making it bigger that you get with zooming in.

The goal was to create a means to scrape the text from PDF's so I could put them into a text editor and adjust the colors, fonts, etc to be easier to read. As mentioned, the python version of this was able to convert a wide variety of PDFs since it used OpenCV and Tesseract to extract the text from an image file that was created from a page in the pdf. As you can imagine this operation is expensive and it would take a few minutes to process a fairly large pdf. More importantly, I use a few different laptops for school depending on which one wants to cooperate on the given day, so this needed to be portable. The python version required installing python, poppler, and tesseract. You also had to set environment variables.

I began looking for a better portable solution. Initially I began to look into C or possibly C++ as options, primarily since Tesseract is mostly in C++, but then I came across Rust and it seemed interesting, so I began learning more. After reading ”The Book”, going through a few rounds of Rustlings, and banging my head on the wall at a Leptos/Actix app attempt, I decided to go back to this project. This seemed like a great candidate for Rust and for me to learn more, but I needed to find a GUI framework to facilitate my build. For this project I ended up using slint. Which was a fairly enjoyable experience for this simple app. I haven't yet had to worry about converting the pdf's to images or integrating Tesseract.

This currently uses the pdf-extract crate to handle extraction, and rusty file dialog to handle cross platform file prompts. It uses the std::fs crate to write to the file system. In my testing across various environments, it is cross platform, though more particular about pdfs that its python incarnation. It seems to like PDFs where text has been particularly defined, I have not had luck with PDFs which have text that is an unselectable, such as within an image (where OCR would provide benefit). I can use this for now, and if OCR is needed, add that later, or bring out the python version. This rust version takes about 10 seconds to process a 500 page pdf. The python version took considerably longer, though I don't remember exactly, and can add benchmarks later if I build it again.

This app is a GUI, so once you download, run cargo run and it should present you with a window with an Open file button. Once you click that, you can select a file, then it will process the file. Once it's done, you'll be prompted again to save the output.

Here's the repo:


Thanks for reading, and happy new year.