DEV Community

Alexandr
Alexandr

Posted on

2

When Files Ask for a Password: A Developer's Solution

In my online world, everything was simple—a login and password were all it took: familiar, secure, and convenient.

The Challenge

Then I stumbled upon a parallel reality: password-protected files like PDF, DOC, ZIP, and more. This wasn’t a rare glitch but a widespread practice in some industries, reminiscent of the floppy disk era. My program, built for modern interactions, would freeze at the sight of such files, bluntly declaring:

"Sorry, we don’t work with these things."

I wasn’t willing to accept this limitation or force users to change long-standing habits. The solution was clear: empower the system to handle these files.

The Journey

PDFs:

I began with PDFs—the cornerstone of document workflows. After testing several PHP libraries from GitHub, which worked until confronted with “quirky” PDFs (errant line breaks or documents that cheekily included /encrypt twice), I discovered qpdf. This external tool reliably handled even the most exotic PDFs.

Office Files:

With .DOCX files, the process was relatively smooth. But the venerable .DOC? Some companies cling to it like a cherished relic, and PHP libraries for this format are scarce. Eventually, msoffcrypto-tool proved to be a true lifesaver.

Archives:

Since I was already integrating external programs via Symfony/Process, I turned to the time-tested 7-Zip for handling archives.

Introducing Lumos

Thus was born Lumos—a cohesive library combining all these tools to effortlessly handle password-protected files. The project is available on GitHub. I’m not expecting accolades or pull requests; I just hope it makes another developer’s life a little easier.


Have you ever encountered password-protected files?

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
xwero profile image
david duymelinck

I haven't encountered password protected documents that needed to be processed.
But I like the legwork you did!

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay