Skip to main content

What is PDFlex?

PDFlex is a powerful PDF processing toolkit for Python. It provides robust tools for PDF validation, text extraction, merging (with custom separator pages), searching, and more—all built to streamline your PDF automation workflows.

Features

  • PDF Validation: Quickly verify if a file is a valid PDF.
  • Text Extraction: Extract text from PDFs using either PyMuPDF or PyPDF.
  • Directory Processing: Process entire directories of PDFs for text extraction.
  • PDF Merging: Merge multiple PDF files into one, automatically inserting a custom separator page between documents.
    • The separator page displays the title (derived from the filename) with underscores and hyphens removed.
    • Supports both portrait and landscape separator pages (ideal for lecture slides).
  • PDF Searching: Recursively search for PDFs in a directory based on filename patterns (e.g., numeric float prefixes).

Quick Start

Installation

PDFlex is available on PyPI. To install using pip:

pip install -U pdflex

Alternatively, install in an isolated environment with pipx:

pipx install pdflex

For the fastest installation using uv:

uv tool install pdflex

Usage

Command-Line Interface (CLI)

PDFlex provides a convenient CLI for merging and searching PDFs. The CLI supports two primary commands: merge and search.

Merge Command

Merge multiple PDF files into a single document while automatically inserting a separator page before each document.

Usage:

pdflex merge /path/to/file1.pdf /path/to/file2.pdf -o merged_output.pdf

Add the --landscape flag to create separator pages in landscape orientation:

pdflex merge /path/to/file1.pdf /path/to/file2.pdf -o merged_output.pdf --landscape

Search and Merge Command

Search for PDF files in a directory based on filename filters (or search for lecture slides with numeric float prefixes) and merge them into one PDF.

Usage:

  • General Search:

    pdflex search /path/to/search -o merged_output.pdf --prefix "Chapter" --suffix ".pdf"
    
  • Lecture Slides Merge: (Merges all PDFs whose filenames start with a numeric float prefix like 1.2_, 3.2_, etc., in sorted order. Separator pages will be in landscape orientation.)

    pdflex search /path/to/algorithms-and-computation -o merged_lectures.pdf --lecture
    

Python API Usage

You can also use PDFlex directly from your Python code. Below are examples for some common tasks.

Merging PDFs with Separator Pages

from pathlib import Path
from pdflex.merge import merge_pdfs

# List of PDF file paths to merge
pdf_files = [
    "/path/to/document1.pdf",
    "/path/to/document2.pdf"
]

# Merge files, using landscape separator pages (ideal for lecture slides)
merge_pdfs(pdf_files, output_path="merged_output.pdf", landscape=True)

Searching for PDFs by Filename

from pdflex.search import search_pdfs, search_numeric_prefixed_pdfs

# General search: Find PDFs that start with a prefix and/or end with a suffix
pdf_list = search_pdfs("/path/to/search", prefix="Chapter", suffix=".pdf")
print("Found PDFs:", pdf_list)

# Lecture slides: Find PDFs with numeric float prefixes (e.g., "1.2_Intro.pdf")
lecture_slides = search_numeric_prefixed_pdfs("/path/to/algorithms-and-computation")
print("Found lecture slides:", lecture_slides)

Contributing

Contributions are welcome! Whether it's bug reports, feature requests, or code contributions, please feel free to:

  1. Open an issue
  2. Submit a pull request
  3. Improve documentation.
  4. Share your ideas!

Acknowledgments

This project is built upon several awesome PDF open-source projects:


License

PDFlex is released under the MIT license.
Copyright (c) 2020 to present PDFlex and contributors.

thematic-break

Metadata

Release files for pdflex 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdflex 0.1.9
File Size Uploaded Provenance Actions
pdflex-0.1.9.tar.gz 283.2 kB With provenance Details for pdflex-0.1.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pdflex 0.1.9
File Interpreter ABI Platform Actions
pdflex-0.1.9-py3-none-any.whl Python 3 none any Details for pdflex-0.1.9-py3-none-any.whl

Total release size: 296.1 kB

Release files / pdflex-0.1.9.tar.gz

Download URL pdflex-0.1.9.tar.gz
Size 283.2 kB
Tags Source
SHA-256 checksum
How to use checksums
19b58a45ae8f621489a1a5ebae640e12d265cfa2e73456ba8a8f3c589caf0800
BLAKE2b-256 checksum
How to use checksums
96a506f56c08f6311afd6e8258fca6fa020685871abb688f4da7b4ffb7f3bae5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 20, 2025.

Transparency log

Release files / pdflex-0.1.9-py3-none-any.whl

Download URL pdflex-0.1.9-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a68fa7fa52555a16e134bb5a80e3232c630d10f9bf5b9fa7ce041c19bb724ca4
BLAKE2b-256 checksum
How to use checksums
15658753297a746099252e87044678d2c5283bda838181ce41e1866f49164858
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 20, 2025.

Transparency log

Security for pdflex 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pdflex-0.1.9.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 20, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page