Skip to content

Converting a PDF File to HTML: pdf2htmlEX

An older yet effective tool: installing and running it with Docker
How to convert a PDF file to HTML efficiently. I encountered this requirement when looking to convert my own resume from PDF to HTML without compromising the visual layout.
I discovered pdf2htmlEX. However, since it hasn't seen updates since 2015, building it natively introduces dependency issues.
It relies heavily on poppler-utils and the Poppler library.

While poppler-utils provides conversion tools like pdftohtml and pdftotext, the layout quality is rarely acceptable for pixel-accurate resumes.

We can use Docker instead, as a prebuilt container image has been maintained by community member bwits.

1 - Installing Docker

You can install Docker via Snap or your distribution's native package manager.
To ensure stability and proper socket permissions, I recommend the system package manager: sudo apt install docker.io.

To execute Docker commands without invoking sudo every time, create a docker group and add your user:

sudo groupadd docker
sudo usermod -aG docker $USER


Log out and log back in (or restart the docker service) for group membership to take effect.

Verify your setup with:

docker run hello-world

2 - Pulling the pdf2htmlEX Docker Image

sudo docker pull bwits/pdf2htmlex

To convert your PDF document:

docker run -ti --rm -v $(pwd):/pdf bwits/pdf2htmlex pdf2htmlEX [args] myfile.pdf

Command flags explained:

docker run: Runs a command in a new container
-ti: Shorthand for --interactive + --tty, keeping STDIN open and allocating a pseudo-TTY
--rm: Automatically removes the container when it exits
-v: Bind mounts a local directory inside the container (here, mounting the current directory $(pwd) to /pdf)

To make this command reusable, define an alias in your ~/.zshrc or ~/.bashrc:
alias pdf2htmlEX="docker run -ti --rm -v $(pwd):/pdf bwits/pdf2htmlex pdf2htmlEX"

Now convert documents directly:

pdf2htmlEX --zoom=2 myfile.pdf

The --zoom flag scales rendering quality. View all options via:
pdf2htmlEX --help

References:
https://www.wild-inter.net/posts/pdf2htmlEX-on-docker
https://github.com/coolwanglu/pdf2htmlEX
https://gitlab.freedesktop.org/poppler/poppler
https://doc.ubuntu-fr.org/poppler-utils
juniko
2 min