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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdfmargins-0.1.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

pdfmargins-0.1.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdfmargins-0.1.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.8 Linux/6.1.96

File hashes

Hashes for pdfmargins-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c2ae02a78151e158689b5ca066c206ed4a30639ba7c555954fb45051f335f6cc
MD5 47fcd6a7a68677eb4be7fd17aaa2fbcb
BLAKE2b-256 8c4ec2f397a74a4fd694cdb553feca7de1b1f941917dac573b0723cce02227f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdfmargins-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.8 Linux/6.1.96

File hashes

Hashes for pdfmargins-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 34360410d198b9bb2c14fb36cdee041ae576c470cac3a9fc47ed776ce7c6725a
MD5 2f60728fb073c55b23d8c11f418189f3
BLAKE2b-256 6a01fcb274a14136a3cd2d9ee85ba5be6b5b6bd12aee0c1e2235fbc18ed4a176

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

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