Skip to main content

Slice specific pages from a PDF and copy their text to the clipboard — for building shorter LLM contexts.

Project description

pdf-prompt-slicer

A tiny CLI that slices specific pages out of a PDF and copies the extracted text to your clipboard — so you can feed an LLM a focused subset of a document instead of uploading the whole thing.

  • Pick pages individually or by range: "[1, 2, 3-6]"
  • Get a new, shorter PDF saved next to the original
  • Get the raw text of those pages on your clipboard, ready to paste
  • Optional clipboard-only mode when you don't need a new PDF

Install (simplest)

Requires uv. If you don't have it:

# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Then install this tool in one line:

uv tool install pdf-prompt-slicer

That puts a pdfslice command on your PATH. You can now run it from anywhere.

Prefer pip? pipx install pdf-prompt-slicer works the same way.

To upgrade later: uv tool upgrade pdf-prompt-slicer To uninstall: uv tool uninstall pdf-prompt-slicer

Usage

pdfslice <path_to_pdf> "<pages>" [-c]

Arguments

  • <path_to_pdf> — path to the source PDF.
  • <pages> — a list of pages or ranges. Brackets are optional; whitespace is fine. Examples: "[1, 2, 3-6]", "1,2,3-6", "4-4", "7".
  • -c, --clipboard-only — copy text to the clipboard only; do not write a sliced PDF.

Examples

Slice pages 1, 2, and 3 through 6 into a new PDF and copy their text:

pdfslice paper.pdf "[1, 2, 3-6]"

Just copy the text (no new PDF):

pdfslice paper.pdf "[1, 2, 3-6]" -c

Output

  • The sliced PDF is saved next to the original with _sliced_<n> appended to the filename. paper.pdfpaper_sliced_1.pdf. Running again produces paper_sliced_2.pdf, etc. — existing files are never overwritten.
  • The combined text of all selected pages (separated by blank lines) is placed on the system clipboard.

Running without installing

From a clone of the repo:

uv run --script run.py <pdf> "[1, 3-5]"

uv reads the inline script metadata at the top of run.py and sets up a temporary env with the right dependencies — no manual install step.

Development

git clone https://github.com/ChuckySRB/PDFPromptSlicer
cd PDFPromptSlicer
uv sync
uv run pdfslice test_data/your.pdf "[1-3]"

The project layout:

PDFPromptSlicer/
├── pyproject.toml
├── run.py                    # inline-deps entry point (no install needed)
├── src/pdf_prompt_slicer/
│   ├── __init__.py
│   ├── __main__.py           # enables `python -m pdf_prompt_slicer`
│   └── cli.py                # real implementation + `main()`
└── test_data/                # gitignored; for local testing

Dependencies

On Linux, pyperclip needs either xclip or xsel installed for clipboard access. macOS and Windows work out of the box.

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

pdf_prompt_slicer-0.1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

pdf_prompt_slicer-0.1.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdf_prompt_slicer-0.1.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pdf_prompt_slicer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 516d8df370893cb4d93acba1a29b3ebdef88af4001baa773c63babd3879d5078
MD5 9c0c9a08684d6970392a5ca5504e0f2f
BLAKE2b-256 34ee4b42a54003d2147cbd30cadb0b4621ac9ee4d73f1467bd640ebadd23976e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdf_prompt_slicer-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pdf_prompt_slicer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6baf4dc2d6bd8ac751e590e00666183b1544c9fcce408394ab2f94341e63970a
MD5 e31607ca734ae135a1dfaf794cbcdbe9
BLAKE2b-256 575f57e735e1369c915100ce9585cf0552c93e30462255262004df7b9bf76d50

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