Skip to main content

Add margins to PDFs

I have a tablet with a pen as ebook-reader. I like to make notes on the side of the PDFs when reading. Often there is not enough space on the margins.

I also like to draw diagrams and notes on the PDF. There is not enough space at the top and bottom. This leads to bad nodes and diagrams I can not decypher later.

This tool adds margins around the text. With this I have enough space for my thoughts and ideas and space to learn.

Features

  • Add marigins around the text
  • Fixed points as margin (e.g. 100)
  • Relative margin (e.g. left=0.3)

Before:

before

After:

after

## Installation

To install the `pdfmargins` package, use one of the following commands:

**CLI Only**:
If you only need the command-line interface, run:
```bash
pip3 install pdfmargins

CLI + Gradio App: If you want to include the Gradio app as well, use:

poetry install pdfmargins[app]

CLI + FastAPI API: To include the FastAPI API, run:

poetry install pdfmargins[api]

All Components (CLI, Gradio App, FastAPI API): If you want to install everything, use:

poetry add pdfmargins[all]

From within the project: If you cloned the project, run in the project root:

poetry install --with all

Verifying the Installation

To verify that the installation was successful, you can run the CLI command:

pdfmargins --help
pdfmargins-app --help # if installed
pdfmargins-api --help # if installed

This should display the help information for the command-line interface.

Usage

See scripts/example_usage.sh for a runnable script, that is also checked by the test-suite (e2e).

Common use-case is to run

python3 cli.py path/to/pdf-file.pdf

This creates a file called path/to/pdf-file.margins.pdf as output.

Or you can process a directory via

python3 cli.py path/to/dir/with/pdfs/

If there is a path/to/dir/with/pdfs/a.pdf there is now a path/to/dir/with/pdfs/a.margins.pdf as output.

If you want to know more, check

python3 cli.py --help

More information

If you nee to know details, check out pdfmargins/cli.py. It is pretty straightforward.

Limitations and next Steps

  • Output-directory, not only suffix for output-files
  • FastAPI server in Dockerfile to make installation easy (with Gradio UI)
  • Make it intallable (as python-package)
  • Add nix-package
  • Detect if 2 columns and be smart where to add margins (1 column, only right margin)
  • Add background, like raster, dots, etc.

Next steps

  • Make it installable
  • Push to pypi
  • Set into metadata that margins were added
  • One or two columns?

Thank you

This is just a wrapper around

  • pypdf

Metadata

Release files for pdfmargins 0.1.1

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

Source distribution (sdist)

Source distribution for pdfmargins 0.1.1
File Size Uploaded
pdfmargins-0.1.1.tar.gz 10.3 kB Details

Built distribution (wheel)

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

Total release size: 22.6 kB

Release files / pdfmargins-0.1.1.tar.gz

Download URL pdfmargins-0.1.1.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c2ae02a78151e158689b5ca066c206ed4a30639ba7c555954fb45051f335f6cc
BLAKE2b-256 checksum
How to use checksums
8c4ec2f397a74a4fd694cdb553feca7de1b1f941917dac573b0723cce02227f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.8 Linux/6.1.96

Release files / pdfmargins-0.1.1-py3-none-any.whl

Download URL pdfmargins-0.1.1-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34360410d198b9bb2c14fb36cdee041ae576c470cac3a9fc47ed776ce7c6725a
BLAKE2b-256 checksum
How to use checksums
6a01fcb274a14136a3cd2d9ee85ba5be6b5b6bd12aee0c1e2235fbc18ed4a176
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.8 Linux/6.1.96

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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