PDF-Helper
A simple python package that helps with doing simple stuff with PDFs.
Features
- Bundle: Bundle multiple files into one PDF
- PDF inputs
- Image inputs (e.g. PNG, JPG, etc.)
- Markdown inputs
- Merge PDFs: Merge multiple PDFs into one PDF
- Split PDFs: Split a PDF into multiple PDFs, each containing a range of pages
- Export as image: Export designated pages from a PDF as image files
- Remove pages: Remove designated pages from a PDF
- Extract text: Export text from a PDF file and optionally save it to a text file
- Recipe system: Chain multiple operations together using YAML recipe files
- Add watermark: Overlay selectable vector text or an image on PDF pages
- Encrypt a PDF
- Decrypt a PDF
- Extract images from a PDF
- Extract links from a PDF
- Set PDF metadata (title, author, etc.)
If you want any other feature to be added, feel free to open an issue or fork the repo and make a merge request after adding your contribution.
Usage
Installation
You can install PDF-Helper via pip:
pip install pdf-helper
# Or use uv to install the tool
uv tool install pdf-helper
And run it using the command line:
pdf-helper <command> [options]
Or you can use uvx to run the package without installing it in a specific python environment:
uvx pdf-helper <command> [options]
You can also clone the repository and use uv run:
git clone https://gitlab.com/CodeWriter21/pdf-helper.git
cd pdf-helper
uv run pdf-helper <command> [options]
Bundle PDFs
Bundle multiple files into one PDF:
pdf-helper bundle <input_file_1> <input_file_2>... <input_file_n> <output_file>
# E.g. Bundle PDFs 1, 2 and 3 into a new PDF
pdf-helper bundle 1.pdf 2.pdf 3.pdf new.pdf
# E.g. Take 1.png, 2.jpg, and 3.png and create a PDF named 123.pdf and override
# if already exists
pdf-helper bundle 1.png 2.jpg 3.png 123.pdf -f
# E.g. Take part1.pdf, image1.png, ending.pdf and bundle them into a PDF named final.pdf
pdf-helper bundle part1.pdf image1.png ending.pdf final.pdf -v
Split PDFs
Split a PDF into multiple PDFs, each containing a range of pages:
pdf-helper split <input_file> <output_folder> -s <split_point_1>,<split_point_2>
# E.g. Split a PDF into three PDFs, one with pages 1-10, the second with pages 11-20 and
# the third with pages 21-end
pdf-helper split my-pdf.pdf my-split-pdfs -s 10,20
# E.g. Split a PDF into PDFs each containing one page
pdf-helper split my-pdf.pdf my-split-pdfs # No need to specify split points
Export PDF pages as image files
Export PDF pages as image files:
pdf-helper to-image <input_file> <output_folder> \
-p <page_number_1>,<page_number_2>,...,<page_number_n> -s <scale_factor>
# E.g. Export pages 1, 2, 3 and 6 from a PDF with scale factor 1
pdf-helper to-image 1.pdf images -p 1-3,6 -s 1
# E.g. Export all pages from a PDF with scale 2
pdf-helper to-image my-pdf.pdf my-images
Remove pages from a PDF
Remove pages from a PDF:
pdf-helper remove-pages <input_file> <output_file> <page_number_1>,<page_number_2>,...,<page_number_n>
# E.g. Remove pages 1, 2, 3 and 6 from a PDF
pdf-helper remove-pages 1.pdf new.pdf 1-3,6
Add watermark to a PDF
Overlay selectable vector text or an image file on PDF pages:
# E.g. Stamp diagonal DRAFT text across all pages
pdf-helper add-watermark my-pdf.pdf watermarked.pdf DRAFT
# E.g. Overlay a logo in the bottom-right corner of pages 1-3
pdf-helper add-watermark my-pdf.pdf watermarked.pdf --watermark-image logo.png \
--position bottom-right --image-scale 0.5 --pages 1-3
# E.g. Stamp text with a custom font (file path or installed name like Arial)
pdf-helper add-watermark my-pdf.pdf watermarked.pdf "DRAFT" --font ./fonts/MyFont.ttf
Not sure which fonts are available? Query them (name or path both work
with --font):
pdf-helper list-fonts
pdf-helper list-fonts arial
See examples/recipes/watermark-showcase.yaml for a recipe
that chains a text watermark and an image watermark in one run.
Export text from a PDF
To extract text from a PDF file and export them to text files you can do as follows:
pdf-helper extract-text <input_file> -o <output_file_name>
# E.g. Extract text from a PDF named my-pdf.pdf and save it to my-text.txt
pdf-helper extract-text my-pdf.pdf -o my-text.txt
Run Recipes
The recipe system lets you chain multiple PDF operations together in a single run using a YAML file. This unlocks features not available through individual CLI commands (e.g. selecting specific pages per file when bundling).
pdf-helper run-recipe <recipe_file.yaml>
# E.g. Run a simple recipe
pdf-helper run-recipe remove-pages.yaml
# E.g. Run with force overwrite and verbose logging
pdf-helper run-recipe bundle-workflow.yaml --force --verbose
Recipe File Format
A recipe is a YAML file with a steps list. Each step has an id, an
operation, input/output paths, and operation-specific options. Steps can
reference each other's outputs using { step: step_id }.
name: "Remove specific pages"
description: "Removes pages 2, 4, 6 from a PDF."
version: "1.0"
steps:
- id: clean
operation: remove_pages
input: document.pdf
pages_to_remove: [2, 4, 6]
output: cleaned.pdf
Supported Operations
| Operation | Status | Description |
|---|---|---|
bundle |
Available | Bundle files with optional per-file page selection |
remove_pages |
Available | Remove pages by 1-based index |
split_pdf |
Available | Split at given page boundaries |
pdf_to_image |
Available | Render pages as PNG images |
extract_text |
Available | Extract text content |
watermark |
Available | Overlay vector text (text) or an image (image) |
encrypt |
Planned | Password-protect PDF (graceful fallback) |
metadata |
Planned | Set title/author/keywords (graceful fallback) |
Operations marked Planned are not yet implemented — the recipe runner logs a warning and copies the input file through, so pipelines don't break.
Watermark text is inserted as selectable vector objects; image watermarks are
raster overlays. Both support position, opacity, rotation, and pages.
Advanced Example: Multi-step Pipeline
# yaml-language-server: $schema=https://gitlab.com/CodeWriter21/pdf-helper/-/raw/master/schemas/recipe-schema.json
name: "Split, Convert, and Extract Pipeline"
version: "1.0"
settings:
temp_dir: "./.recipe-tmp"
steps:
# Step 1: Split the PDF at pages 5 and 10
- id: split
operation: split_pdf
input: report.pdf
split_points: [5, 10]
output_dir: .
output_prefix: "report_part_"
# Step 2: Convert the second chunk to images
- id: to_images
operation: pdf_to_image
input:
step: split
file: report_part_2.pdf
pages: "1-3"
scale: 3
output: ./output/images
# Step 3: Extract text from the first chunk
- id: extract
operation: extract_text
input:
step: split
file: report_part_1.pdf
pages: "1-4"
max_characters: 5000
reverse_lines: true
output: ./output/chapter-1-text.txt
Recipe Settings
| Setting | Default | Description |
|---|---|---|
temp_dir |
./.recipe-tmp |
Directory for intermediate files |
overwrite |
false |
Overwrite existing output files |
cleanup_temp |
false |
Remove temp directory after completion |
Input values (e.g. passwords) can be sourced from environment variables or prompted at runtime:
inputs:
password:
env: PDF_PASSWORD
prompt: "Enter output PDF password"
See examples/recipes/ for more example recipe files.
About
Author: CodeWriter21
GitLab: CodeWriter21/pdf-helper
Donations
Your donations are very welcome: nowpayments.io
You can also consider donating a Star to the repo.
License
This project is licensed under the MIT License.
See the LICENSE
References
Release files for pdf-helper 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pdf_helper-0.5.0.tar.gz | 19.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pdf_helper-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 41.0 kB
Release files / pdf_helper-0.5.0.tar.gz
| Download URL | pdf_helper-0.5.0.tar.gz |
|---|---|
| Size | 19.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
705952fa755837f6d6ce1c61190a9453674d8e4238f2e237574f72ab088cbfb4
|
|
BLAKE2b-256 checksum How to use checksums |
2d44881b8910eb7d7a2dff120bb39d8d3f1b35c160b27623f0a0a6ca48d9b1d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pdf_helper-0.5.0-py3-none-any.whl
| Download URL | pdf_helper-0.5.0-py3-none-any.whl |
|---|---|
| Size | 21.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ec078b6185be988740464a9dfa03b28e68c30a7a7a302cc4182af7bf032a7acc
|
|
BLAKE2b-256 checksum How to use checksums |
14f54cb7719349cb9a2004811cd9fb810ecdb1dbe79674862fef26c325c7cbe0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|