Skip to main content

PDF to semantic HTML conversion.

Project description

PDF to semantic HTML conversion

Transcript contains Python programs whose job is to transcribe PDF into sematic HTML.

transcript.py

: Get semantic HTML from PDFs converted by pdf2htmlEX.

ttf.py

: Recover lost text from PDFs where characters are nothing more than images of themselves.

pdf2html.py

: Batch process a folder full of PDFs ready for transcript.py

Read the docstrings for more information.

Example

PDF before and semantic HTML after

Install

Get Python 3 installed along with latest pdf2htmlEX. e.g. with Homebrew:

brew install python3 pdf2htmlEX

or on Ubuntu/Debian

sudo apt update && sudo apt install -y libfontconfig1 libcairo2 libjpeg-turbo8 ttfautohint
wget -o pdf2htmlEX.deb https://github.com/pdf2htmlEX/pdf2htmlEX/releases/download/v0.18.8.rc1/pdf2htmlEX-0.18.8.rc1-master-20200630-Ubuntu-bionic-x86_64.deb

Check sha256sum pdf2htmlEX.deb matches 4ef2698cbeb6995189ac...

sudo apt install ./pdf2htmlEX.deb
pdf2htmlEX -v

Docker install of pdf2htmlEX is also supported (brew one started failing as of late). This particular image is tested and used in the default config via DOCKER_IMG_TAG.

docker pull
pdf2htmlex/pdf2htmlex:0.18.8.rc2-master-20200820-ubuntu-20.04-x86_64

Install lxml under python3 pip3 install lxml or just run the following and get freetype-py too.

pip3 install -r requirements.txt

Configure

Configure your project path in your .env file and config.py most importantly the DATA_DIR. This can be any folder let's say DATA_DIR=/path/to/pdf-transcript/tests. If you use a docker install of pdf2htmlEX, you'll need to set DOCKER_INSTALL=1 This will mount your data dir to Docker path. DOCKER_IMG_TAG is also configurable. Go ahead create your .env file and add DATA_DIR=...

Your DATA_DIR should end up containing 3 folders: PDF, HTML and HTM if you otherwise stick with default configuration. Create a 'PDF' folder inside and drop your PDFs there.

  • PDF is a folder where your PDFs are.
  • HTML is where pdf2htmlEX output (non-semantic HTML) ends up after running ./pdf2html.py, which just runs pdf2htmlEX with suitable options.
  • HTM is the final destination where semantic HTML gets born after running ./transcript.py.

Run

./pdf2html.py

./transcript.py

When you change configuration within ./transcript.py or tweak some code. You only need to run ./transcript.py

Development process

Set expected (hand-adjusted) output to aim for and improve codebase to get transcript output closer to the ideal semantic output. Make sure your changes don't make output worse for other tests. Use ruff check.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdftranscript-1.0.tar.gz (4.1 MB view details)

Uploaded Source

Built Distribution

pdftranscript-1.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file pdftranscript-1.0.tar.gz.

File metadata

  • Download URL: pdftranscript-1.0.tar.gz
  • Upload date:
  • Size: 4.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.20

File hashes

Hashes for pdftranscript-1.0.tar.gz
Algorithm Hash digest
SHA256 25460a20f123fa15312c44f9179553ba7fbe17278ef5cfc9413e9f4d1c17ed58
MD5 b7491dafbf4c4ce9a8fdc01aaf7c630d
BLAKE2b-256 b718a8c48534625e32653e1b77e4ad0636ecb73fc906dbd4539ba3ff0e546e12

See more details on using hashes here.

File details

Details for the file pdftranscript-1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pdftranscript-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2f425405cbd743adfa37a385b79511663416b1ab9c57bfd94380ac1e3b1f72d
MD5 66596ff6d2749317b81f17aec920ec4f
BLAKE2b-256 7851e5ab9df9cf32e30c797a7c6c00c4eab4f1de1e3d335cbde7f7c83fdd2ffe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page