Skip to main content

Extended PDF Manipulation Toolkit

Project description

PDF2S 🔖

A Swiss Army knife for PDF manipulations with Markdown conversion capabilities

Python 3.8+ License: MIT

Features ✨

  • Merge PDFs with regex filename filtering
  • Split PDFs by:
    • Page ranges (e.g., "1-3,5-8")
    • Fixed page chunks (e.g., every 5 pages)
    • Special "all" keyword for full document split
  • Convert Markdown ↔ PDF:
    • Preserve formatting with custom CSS styles
    • Basic text extraction from PDF to Markdown
  • Extract Images from PDF files:
    • Filter by minimum size
    • Convert to specific formats
    • Automatic output directory creation
  • CLI Interface with intuitive subcommands
  • Pipx Installable for easy system-wide use

Installation 📦

pipx install pdf2s

System Requirements:

  • Python 3.8+
  • libpangocairo-1.0-0 (for WeasyPrint)
    • Ubuntu/Debian: sudo apt-get install libpangocairo-1.0-0

Usage 💻

$ pdf2s --help
Usage: pdf2s [OPTIONS] COMMAND [ARGS]...

Commands:
  merge    Merge PDF files
  split    Split PDF files
  md2pdf   Convert Markdown to PDF
  pdf2md   Convert PDF to Markdown
  pdf2img  Extract images from PDF

Merge PDFs

# Merge all PDFs in directory (sorted)
pdf2s merge ./documents merged.pdf --sort

# Merge only files matching regex pattern
pdf2s merge ./reports final_report.pdf -r 'Q[1-4]_2023'

Split PDFs

# Split into individual pages
pdf2s split input.pdf output_dir

# Split every 5 pages
pdf2s split input.pdf output_dir --pages 5

# Split specific ranges
pdf2s split input.pdf output_dir --ranges "1-3,5-8"

# Split entire document
pdf2s split input.pdf output_dir --ranges "all"

Markdown Conversion

# MD to PDF with custom styling
pdf2s md2pdf input.md output.pdf --style styles.css

# PDF to Markdown
pdf2s pdf2md input.pdf output.md

Extract Images

# Basic usage (creates output in myfile_imgs directory)
pdf2s pdf2img myfile.pdf

# Specify output directory
pdf2s pdf2img myfile.pdf --output-dir extracted_images

# Only extract larger images
pdf2s pdf2img myfile.pdf --min-size 300

# Convert all images to specific formats
pdf2s pdf2img myfile.pdf --formats "jpg,png"

Development 🛠️

  1. Clone repository
  2. Install dependencies:
pipx install poetry
poetry install
  1. Run tests:
poetry run pytest

Distribution Options 📦

Using pipx

The recommended way to install pdf2s is using pipx, which installs the package in an isolated environment:

# Install pipx if you don't have it
pip install --user pipx
python -m pipx ensurepath

# Install pdf2s
pipx install pdf2s

# Update to latest version
pipx upgrade pdf2s

Building Executable with PyInstaller

You can compile pdf2s into a standalone executable:

# Install PyInstaller
pip install pyinstaller

# Create standalone executable
pyinstaller --onefile --name pdf2s src/pdf2s/cli.py

# The executable will be in the dist directory
./dist/pdf2s --help

# Copy to a location in your PATH (optional)
cp ./dist/pdf2s /usr/local/bin/

Publishing to PyPI

To publish the package to PyPI:

# Install build tools
pip install build twine

# Build the distribution packages
python -m build

# Upload to TestPyPI first (optional)
twine upload --repository testpypi dist/*

# Upload to PyPI
twine upload dist/*

Make sure to update the version in pyproject.toml before building a new release.

Contributing 🤝

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a Pull Request

Report issues using the GitHub Issues tracker.

License 📄

This project is licensed under the MIT License - see the LICENSE file for details.

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

pdf2s-0.1.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdf2s-0.1.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file pdf2s-0.1.1.tar.gz.

File metadata

  • Download URL: pdf2s-0.1.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pdf2s-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6a2d2082cb1021e71a59c938656d66d009dab3f2243bd35b09775a78e08ced1c
MD5 71d1272fd77beeb7da469024e510c9f6
BLAKE2b-256 fd4799d1dae0838dc9ed32cc235c228b6feb645d404d8798e1a51a86d30957d1

See more details on using hashes here.

File details

Details for the file pdf2s-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pdf2s-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pdf2s-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4cd7ea642047465be7a7c5da523e507eac6d3aab73c9eb0ed97303fdf62a3ee8
MD5 931a20864e8e4e2849a6bff6caa7ab9d
BLAKE2b-256 77abbdabd54deb5e48cc57b7b5b7295a0a34d24bdae4bf956f83515c24d4e532

See more details on using hashes here.

Supported by

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