pdf2htmlEX converts PDF documents into HTML while preserving searchable text, layout, fonts, and images as closely as possible to the original document.
This repository tracks a maintained fork of pdf2htmlEX with fixes and build tooling for current Poppler and FontForge combinations.
pdf2htmlEX is a command-line converter for turning PDFs into web-friendly HTML output:
- Preserves text as selectable/searchable HTML when possible.
- Extracts and embeds fonts used by the PDF.
- Renders non-text content, figures, and complex backgrounds.
- Supports single-file output or split-page output for dynamic loading.
- Includes options for outlines, annotations, forms, printing support, and background rendering.
In short: if you want to publish a PDF on the web without flattening everything into a giant image, this package is designed for that job.
Compared with the original upstream project, this branch focuses on keeping the project buildable and useful with newer dependency versions, and includes improvements such as:
- bug fixes for edge cases,
- updated Cairo integration,
- out-of-source building support,
- more accurate handling of obscured and partially obscured text,
- transparent-text support improvements, and
- DPI clamping to avoid oversized rendered graphics.
Because pdf2htmlEX depends on tightly matched Poppler and FontForge versions, installation is more specialized than a typical single-package build.
Before choosing a method, clone the repository if you plan to build from source:
git clone https://github.com/pdf2htmlEX/pdf2htmlEX.git
cd pdf2htmlEXIf you just want to use the converter, start with the project releases. The repository includes build tooling for distributing:
- Debian packages,
- AppImages, and
- OCI/Docker container images.
See the GitHub releases page for downloadable artifacts:
Basic install flow:
- Open the releases page.
- Download the artifact that matches your environment, such as a Debian package, AppImage, or container image.
- Install or run that artifact using the standard tool for your platform.
- Verify the installation with
pdf2htmlEX --version.
pdf2htmlEX does not currently provide a supported native macOS build script in this repository. For most Mac users, the easiest way to run it is through Docker. The project's published releases include a Docker/OCI image tarball, but the Docker Hub repository does not currently provide a latest tag.
-
Install Docker Desktop for Mac.
-
Open Docker Desktop once and wait until it says Docker is running.
-
Open the Terminal app on your Mac.
-
Go to the folder where your PDF lives. Example:
cd ~/Downloads
-
Open the latest release page: https://github.com/pdf2htmlEX/pdf2htmlEX/releases.
-
Download the release asset whose name ends in
.tar.gzand starts withpdf2htmlEX-, for examplepdf2htmlEX-0.18.8.rc1-master-20200630-alpine-3.12.0-x86_64.tar.gz. -
Load that image into Docker (replace the filename with the file you downloaded):
docker load -i pdf2htmlEX-0.18.8.rc1-master-20200630-alpine-3.12.0-x86_64.tar.gz
-
Run the converter by mounting your current folder into the container:
docker run --rm -it -v "$PWD:/pdf" pdf2htmlex/pdf2htmlex:0.18.8.rc1-master-20200630-alpine-3.12.0-x86_64 pdf2htmlEX your-file.pdf -
Look in the same folder for the generated HTML file, usually
your-file.html.
If your file is named report.pdf and is in ~/Downloads:
cd ~/Downloads
docker run --rm -it -v "$PWD:/pdf" pdf2htmlex/pdf2htmlex:0.18.8.rc1-master-20200630-alpine-3.12.0-x86_64 pdf2htmlEX report.pdfThat should create report.html in ~/Downloads.
mkdir -p output
docker run --rm -it -v "$PWD:/pdf" pdf2htmlex/pdf2htmlex:0.18.8.rc1-master-20200630-alpine-3.12.0-x86_64 pdf2htmlEX --dest-dir output report.pdfdocker: command not found: Docker Desktop is not installed, or you need to quit and reopen Terminal after installing it.- Docker says it is not running: Start Docker Desktop and wait for it to finish launching.
Unable to find image: The Docker Hublatesttag is not currently published. Download the release.tar.gzimage, rundocker load -i ..., then use the exact tag that Docker prints after loading.- Your PDF has spaces in its filename: Wrap the name in quotes, for example
"My File.pdf". - You used
cd pdf2htmlEXbut your PDF is somewhere else:pdf2htmlEXreads files from the folder you mount into Docker. Eithercdinto the PDF's folder first, or mount a different folder.
Replace sample.pdf with your own file name:
cd ~/Downloads
docker load -i pdf2htmlEX-0.18.8.rc1-master-20200630-alpine-3.12.0-x86_64.tar.gz
docker run --rm -it -v "$PWD:/pdf" pdf2htmlex/pdf2htmlex:0.18.8.rc1-master-20200630-alpine-3.12.0-x86_64 pdf2htmlEX sample.pdfFor most source installs on supported Linux systems, use the helper scripts in buildScripts/.
From the repository root:
./buildScripts/buildInstallLocallyAptStep by step, this is:
- Clone the repository and change into it.
- Run
./buildScripts/buildInstallLocallyApt. - Let the script install the required build tools and development libraries.
- Wait while the script downloads and builds compatible Poppler and FontForge versions.
- Let the script build and install
pdf2htmlEX. - Confirm the binary is available with
pdf2htmlEX --version.
This script installs build dependencies, downloads compatible Poppler and FontForge sources, builds them statically, then builds and installs pdf2htmlEX.
./buildScripts/buildInstallLocallyAlpineTypical Alpine flow:
- Clone the repository and change into it.
- Run
./buildScripts/buildInstallLocallyAlpine. - Allow the script to install Alpine build dependencies.
- Wait for the helper script to build the pinned dependency stack and
pdf2htmlEX. - Verify the installation with
pdf2htmlEX --version.
Run a quick smoke test on any PDF file:
pdf2htmlEX sample.pdfIf the command succeeds, you should see an HTML file generated in the current directory.
If you want more detail on the build pipeline and release artifacts, read:
buildScripts/Readme.md
The command format is:
pdf2htmlEX [options] <input-filename> [output-filename]Convert document.pdf into document.html in the current directory:
pdf2htmlEX document.pdfpdf2htmlEX report.pdf report.htmlpdf2htmlEX --dest-dir output report.pdfpdf2htmlEX --first-page 3 --last-page 5 report.pdf excerpt.htmlpdf2htmlEX --embed cfijo report.pdf report.htmlThe --embed string controls whether CSS, fonts, images, JavaScript, and outlines are embedded directly in the HTML or emitted as separate files.
pdf2htmlEX --split-pages 1 --page-filename page%03d.html report.pdf index.htmlThis is useful when serving large documents one page at a time.
pdf2htmlEX --font-size-multiplier 1 --zoom 25 input.pdf output.htmlThis combination is recommended in this fork when maximum layout accuracy matters and you can scale the resulting HTML in your own viewer.
pdf2htmlEX --correct-text-visibility 2 input.pdf output.htmlModes are:
0: no visibility calculations,1: fully occluded text goes to the background layer,2: partially occluded text can also be pushed into the background layer.
Here are some of the most useful options when using the package.
--first-page <n>: start conversion at a specific page.--last-page <n>: stop conversion at a specific page.
--zoom <ratio>: scale the output directly.--fit-width <px>/--fit-height <px>: constrain page dimensions.--hdpi <dpi>/--vdpi <dpi>: control image rendering DPI.--use-cropbox 0|1: choose CropBox vs MediaBox.
--dest-dir <dir>: choose an output directory.--split-pages 0|1: emit one file per page.--page-filename <pattern>: choose page file names.--css-filename <name>: set the CSS file name if CSS is external.--outline-filename <name>: set the outline file name if outlines are external.
--process-nontext 0|1: include non-text objects.--process-outline 0|1: include bookmarks/outlines.--process-annotation 0|1: include annotations.--process-form 0|1: include PDF forms.--printing 0|1: enable or disable printing support.--fallback 0|1: use larger but more compatible output.
--font-format <format>: font output format, defaultwoff.--embed-external-font 0|1: embed matched local fonts when PDFs do not contain them.--decompose-ligature 0|1: expand ligatures such asfi.--turn-off-ligatures 0|1: discourage browser ligature substitution.--auto-hint 0|1: generate hints using FontForge.
--space-threshold <ratio>: adjust space insertion sensitivity.--font-size-multiplier <ratio>: work around browser font-size rounding.--space-as-offset 0|1: treat spaces as positioning offsets.--tounicode <-1|0|1>: control ToUnicode mapping behavior.--optimize-text 0|1: reduce the number of generated text elements.--correct-text-visibility <0|1|2>: improve obscured-text handling.
A practical workflow for using this package looks like this:
- Install a packaged release, or build with
buildScripts/buildInstallLocallyApt. - Run
pdf2htmlEX input.pdfto create HTML. - Open the resulting HTML in a browser.
- If layout fidelity is not good enough, retry with options like:
--zoom 25 --font-size-multiplier 1--fallback 1--correct-text-visibility 1or2
- If the output should be served as a document viewer, consider
--split-pages 1and external assets.
Depending on the options you choose, pdf2htmlEX may generate:
- one standalone
.htmlfile, - a main HTML file plus external
.css, font, image, JavaScript, or outline files, - one file per page when
--split-pages 1is used.
If everything is embedded, distribution is easiest. If assets are external, caching and incremental loading can be better.
- If output is visually inaccurate, try
--zoom 25 --font-size-multiplier 1. - If text that should be hidden is showing through, try
--correct-text-visibility 1or2. - If file size becomes too large, avoid high DPI unless necessary and consider externalized assets instead of fully embedded output.
- If fonts render incorrectly, experiment with
--font-format,--embed-external-font,--decompose-ligature, and--tounicode. - If you are building from source, prefer the repository's build scripts rather than attempting a manual system-library build.
- Build/install overview:
buildScripts/Readme.md - General contribution guidance:
CONTRIBUTING.md - License details:
LICENSE - Changelog/history:
ChangeLog - Test notes:
pdf2htmlEX/test/README.md
pdf2htmlEX as a whole is licensed under GPLv3+. Some bundled resources use more permissive licenses; see LICENSE for details.
# Convert a PDF to HTML
pdf2htmlEX input.pdf
# Convert into a specific directory
pdf2htmlEX --dest-dir output input.pdf
# Convert only pages 1 through 10
pdf2htmlEX --first-page 1 --last-page 10 input.pdf partial.html
# Split each page into separate page files
pdf2htmlEX --split-pages 1 input.pdf output.html
# Prioritize rendering accuracy
pdf2htmlEX --zoom 25 --font-size-multiplier 1 input.pdf output.html