pdf-watermark


Namepdf-watermark JSON
Version 2.2.1 PyPI version JSON
download
home_pageNone
SummaryA python CLI tool to add watermarks to a PDF
upload_time2024-04-25 20:51:29
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT License Copyright (c) [2023] [Bastien Le Chenadec] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords pdf watermark cli
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pdf-watermark

A python CLI tool to add watermarks to a PDF. Allows for processing whole directories while keeping the directory structure.

## Description

There are multiple similar tools out there but I couldn't find one that really suited my needs. This project also serves as an excuse to play with building and distributing a python CLI tool.

With this tool you can add a watermark to a PDF file. The watermark can either be a text string that you provide, or an image (PNG being the recommanded format).

This tool provides two commands.
* **insert**: The watermark is placed once on each page at a specific position.
* **grid**: The watermark is repeated multiple times on each page in a grid pattern.

Below is an example of a PDF before using this tool, after using this tool with the *grid* command and a text watermark, and after using this tool with the *grid* command and an image watermark.

<p align="middle">
  <img src="https://raw.githubusercontent.com/bastienlc/pdf-watermark/master/images/before.png" width="29%" />
  <img src="https://raw.githubusercontent.com/bastienlc/pdf-watermark/master/images/text.png" width="29%" />
  <img src="https://raw.githubusercontent.com/bastienlc/pdf-watermark/master/images/image.png" width="29%" />
</p>

Many options are available to customize the watermark, such as the position, the opacity, the angle, the color, the font, the size, etc. A detailed list of options is available below.

## Getting Started

### Dependencies

* This project was built with python 3.11. However it should also run just fine with older versions.
* See `requirements.txt` for the list of dependencies.
* Some options require parts of the `poppler` library to be installed (--save-as-image and --unselectable). Please refer to the [pdf2image](https://pypi.org/project/pdf2image/) or [poppler](https://poppler.freedesktop.org/) documentation for installation instructions.

### Installing

This package is available on PyPi.

```
pip install pdf-watermark
```

### Usage

**TLDR**
```bash
watermark grid input.pdf "watermark text" -s output.pdf # Grid pattern for a single file
watermark insert input_folder "watermark_image.png" # Insert image for a whole directory, overwriting the input files
```

**Detailed usage**
```
Usage: watermark [OPTIONS] COMMAND [ARGS]...

  Add a watermark to one or more PDF files.

  The watermark can be repeated in a grid pattern using the grid command, or
  inserted at a specific position using the insert command.

Options:
  --help  Show this message and exit.

Commands:
  grid    Add a watermark in a grid pattern.
  insert  Add a watermark at a specific position.
```

**insert** command:
```
Usage: watermark insert [OPTIONS] FILE WATERMARK

  Add a watermark at a specific position.

  Add a WATERMARK to one or more PDF files referenced by FILE. WATERMARK can
  be either a string or a path to an image file. FILE can be a single file or
  a directory, in which case all PDF files in the directory will be
  watermarked.

Options:
  -y, --y FLOAT                   Position of the watermark with respect to
                                  the vertical direction. Must be between 0
                                  and 1.
  -x, --x FLOAT                   Position of the watermark with respect to
                                  the horizontal direction. Must be between 0
                                  and 1.
  -ha, --horizontal-alignment TEXT
                                  Alignment of the watermark with respect to
                                  the horizontal direction. Can be one of
                                  'left', 'right' and 'center'.
  -s, --save TEXT                 File or folder to save results to. By
                                  default, the input files are overwritten.
  -o, --opacity FLOAT             Watermark opacity between 0 (invisible) and
                                  1 (no transparency).
  -a, --angle FLOAT               Watermark inclination in degrees.
  -tc, --text-color TEXT          Text color in hexadecimal format, e.g.
                                  #000000.
  -tf, --text-font TEXT           Text font to use. Supported fonts are those
                                  supported by reportlab.
  -ts, --text-size INTEGER        Text font size.
  --unselectable                  Make the watermark text unselectable. This
                                  works by drawing the text as an image, and
                                  thus results in a larger file size.
  -is, --image-scale FLOAT        Scale factor for the image. Note that before
                                  this factor is applied, the image is already
                                  scaled down to fit in the boxes.
  --save-as-image                 Convert each PDF page to an image. This
                                  makes removing the watermark more difficult
                                  but also increases the file size.
  --dpi INTEGER                   DPI to use when saving the PDF as an image.
  --help                          Show this message and exit.
```

**grid** command:
```
Usage: watermark grid [OPTIONS] FILE WATERMARK

  Add a watermark in a grid pattern.

  Add a WATERMARK to one or more PDF files referenced by FILE. WATERMARK can
  be either a string or a path to an image file. FILE can be a single file or
  a directory, in which case all PDF files in the directory will be
  watermarked.

Options:
  -h, --horizontal-boxes INTEGER  Number of repetitions of the watermark along
                                  the horizontal direction.
  -v, --vertical-boxes INTEGER    Number of repetitions of the watermark along
                                  the vertical direction.
  -m, --margin                    Wether to leave a margin around the page or
                                  not. When False (default), the watermark
                                  will be cut on the PDF edges.
  -s, --save TEXT                 File or folder to save results to. By
                                  default, the input files are overwritten.
  -o, --opacity FLOAT             Watermark opacity between 0 (invisible) and
                                  1 (no transparency).
  -a, --angle FLOAT               Watermark inclination in degrees.
  -tc, --text-color TEXT          Text color in hexadecimal format, e.g.
                                  #000000.
  -tf, --text-font TEXT           Text font to use. Supported fonts are those
                                  supported by reportlab.
  -ts, --text-size INTEGER        Text font size.
  --unselectable                  Make the watermark text unselectable. This
                                  works by drawing the text as an image, and
                                  thus results in a larger file size.
  -is, --image-scale FLOAT        Scale factor for the image. Note that before
                                  this factor is applied, the image is already
                                  scaled down to fit in the boxes.
  --save-as-image                 Convert each PDF page to an image. This
                                  makes removing the watermark more difficult
                                  but also increases the file size.
  --dpi INTEGER                   DPI to use when saving the PDF as an image.
  --help                          Show this message and exit.
```

## Contributing

Contributions are always welcome, whether it is for bug fixes, new features or just to improve the documentation and code quality. Feel free to open an issue or a pull request.

### Building the package

Make sure you have `setuptools` and `build` installed.

```
pip install setuptools build
python3 -m build
```

### Editable install for development

```
pip install -e .
```

### Checklist before opening a pull request

* The code is formatted with `black` and `isort`.
* The tests pass.
* The readme is updated if necessary (especially if the command line interface changes).

## Authors

[@bastienlc](https://github.com/bastienlc)

## Version History

* 1.0.0
    * Add text watermark support.
    * Add image watermark support.
    * Add CLI.
    * Add complex directories support.
* 2.0.0
    * Move tool to subcommand **grid**.
    * Add **insert** command.
* 2.1.0
    * Add --unselectable and --save-as-image options.
    * Fix bug with temporary files on Windows.
* 2.1.2
    * Fix missing Poppler dependancy.
    * Add test and lint to CI.
* 2.2.0
    * Support PDFs with pages of different sizes.
* 2.2.1
    * Support line breaks in text watermark.

## License

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

## Acknowledgments

* [readme template](https://gist.github.com/DomPizzie/7a5ff55ffa9081f2de27c315f5018afc)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pdf-watermark",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "pdf, watermark, cli",
    "author": null,
    "author_email": "Bastien Le Chenadec <bastien.lechenadec@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/00/6e/c6823684e7ebd7850a36f9c6a90138334ae3683a5c7ea0a3ebfb552177d9/pdf_watermark-2.2.1.tar.gz",
    "platform": null,
    "description": "# pdf-watermark\n\nA python CLI tool to add watermarks to a PDF. Allows for processing whole directories while keeping the directory structure.\n\n## Description\n\nThere are multiple similar tools out there but I couldn't find one that really suited my needs. This project also serves as an excuse to play with building and distributing a python CLI tool.\n\nWith this tool you can add a watermark to a PDF file. The watermark can either be a text string that you provide, or an image (PNG being the recommanded format).\n\nThis tool provides two commands.\n* **insert**: The watermark is placed once on each page at a specific position.\n* **grid**: The watermark is repeated multiple times on each page in a grid pattern.\n\nBelow is an example of a PDF before using this tool, after using this tool with the *grid* command and a text watermark, and after using this tool with the *grid* command and an image watermark.\n\n<p align=\"middle\">\n  <img src=\"https://raw.githubusercontent.com/bastienlc/pdf-watermark/master/images/before.png\" width=\"29%\" />\n  <img src=\"https://raw.githubusercontent.com/bastienlc/pdf-watermark/master/images/text.png\" width=\"29%\" />\n  <img src=\"https://raw.githubusercontent.com/bastienlc/pdf-watermark/master/images/image.png\" width=\"29%\" />\n</p>\n\nMany options are available to customize the watermark, such as the position, the opacity, the angle, the color, the font, the size, etc. A detailed list of options is available below.\n\n## Getting Started\n\n### Dependencies\n\n* This project was built with python 3.11. However it should also run just fine with older versions.\n* See `requirements.txt` for the list of dependencies.\n* Some options require parts of the `poppler` library to be installed (--save-as-image and --unselectable). Please refer to the [pdf2image](https://pypi.org/project/pdf2image/) or [poppler](https://poppler.freedesktop.org/) documentation for installation instructions.\n\n### Installing\n\nThis package is available on PyPi.\n\n```\npip install pdf-watermark\n```\n\n### Usage\n\n**TLDR**\n```bash\nwatermark grid input.pdf \"watermark text\" -s output.pdf # Grid pattern for a single file\nwatermark insert input_folder \"watermark_image.png\" # Insert image for a whole directory, overwriting the input files\n```\n\n**Detailed usage**\n```\nUsage: watermark [OPTIONS] COMMAND [ARGS]...\n\n  Add a watermark to one or more PDF files.\n\n  The watermark can be repeated in a grid pattern using the grid command, or\n  inserted at a specific position using the insert command.\n\nOptions:\n  --help  Show this message and exit.\n\nCommands:\n  grid    Add a watermark in a grid pattern.\n  insert  Add a watermark at a specific position.\n```\n\n**insert** command:\n```\nUsage: watermark insert [OPTIONS] FILE WATERMARK\n\n  Add a watermark at a specific position.\n\n  Add a WATERMARK to one or more PDF files referenced by FILE. WATERMARK can\n  be either a string or a path to an image file. FILE can be a single file or\n  a directory, in which case all PDF files in the directory will be\n  watermarked.\n\nOptions:\n  -y, --y FLOAT                   Position of the watermark with respect to\n                                  the vertical direction. Must be between 0\n                                  and 1.\n  -x, --x FLOAT                   Position of the watermark with respect to\n                                  the horizontal direction. Must be between 0\n                                  and 1.\n  -ha, --horizontal-alignment TEXT\n                                  Alignment of the watermark with respect to\n                                  the horizontal direction. Can be one of\n                                  'left', 'right' and 'center'.\n  -s, --save TEXT                 File or folder to save results to. By\n                                  default, the input files are overwritten.\n  -o, --opacity FLOAT             Watermark opacity between 0 (invisible) and\n                                  1 (no transparency).\n  -a, --angle FLOAT               Watermark inclination in degrees.\n  -tc, --text-color TEXT          Text color in hexadecimal format, e.g.\n                                  #000000.\n  -tf, --text-font TEXT           Text font to use. Supported fonts are those\n                                  supported by reportlab.\n  -ts, --text-size INTEGER        Text font size.\n  --unselectable                  Make the watermark text unselectable. This\n                                  works by drawing the text as an image, and\n                                  thus results in a larger file size.\n  -is, --image-scale FLOAT        Scale factor for the image. Note that before\n                                  this factor is applied, the image is already\n                                  scaled down to fit in the boxes.\n  --save-as-image                 Convert each PDF page to an image. This\n                                  makes removing the watermark more difficult\n                                  but also increases the file size.\n  --dpi INTEGER                   DPI to use when saving the PDF as an image.\n  --help                          Show this message and exit.\n```\n\n**grid** command:\n```\nUsage: watermark grid [OPTIONS] FILE WATERMARK\n\n  Add a watermark in a grid pattern.\n\n  Add a WATERMARK to one or more PDF files referenced by FILE. WATERMARK can\n  be either a string or a path to an image file. FILE can be a single file or\n  a directory, in which case all PDF files in the directory will be\n  watermarked.\n\nOptions:\n  -h, --horizontal-boxes INTEGER  Number of repetitions of the watermark along\n                                  the horizontal direction.\n  -v, --vertical-boxes INTEGER    Number of repetitions of the watermark along\n                                  the vertical direction.\n  -m, --margin                    Wether to leave a margin around the page or\n                                  not. When False (default), the watermark\n                                  will be cut on the PDF edges.\n  -s, --save TEXT                 File or folder to save results to. By\n                                  default, the input files are overwritten.\n  -o, --opacity FLOAT             Watermark opacity between 0 (invisible) and\n                                  1 (no transparency).\n  -a, --angle FLOAT               Watermark inclination in degrees.\n  -tc, --text-color TEXT          Text color in hexadecimal format, e.g.\n                                  #000000.\n  -tf, --text-font TEXT           Text font to use. Supported fonts are those\n                                  supported by reportlab.\n  -ts, --text-size INTEGER        Text font size.\n  --unselectable                  Make the watermark text unselectable. This\n                                  works by drawing the text as an image, and\n                                  thus results in a larger file size.\n  -is, --image-scale FLOAT        Scale factor for the image. Note that before\n                                  this factor is applied, the image is already\n                                  scaled down to fit in the boxes.\n  --save-as-image                 Convert each PDF page to an image. This\n                                  makes removing the watermark more difficult\n                                  but also increases the file size.\n  --dpi INTEGER                   DPI to use when saving the PDF as an image.\n  --help                          Show this message and exit.\n```\n\n## Contributing\n\nContributions are always welcome, whether it is for bug fixes, new features or just to improve the documentation and code quality. Feel free to open an issue or a pull request.\n\n### Building the package\n\nMake sure you have `setuptools` and `build` installed.\n\n```\npip install setuptools build\npython3 -m build\n```\n\n### Editable install for development\n\n```\npip install -e .\n```\n\n### Checklist before opening a pull request\n\n* The code is formatted with `black` and `isort`.\n* The tests pass.\n* The readme is updated if necessary (especially if the command line interface changes).\n\n## Authors\n\n[@bastienlc](https://github.com/bastienlc)\n\n## Version History\n\n* 1.0.0\n    * Add text watermark support.\n    * Add image watermark support.\n    * Add CLI.\n    * Add complex directories support.\n* 2.0.0\n    * Move tool to subcommand **grid**.\n    * Add **insert** command.\n* 2.1.0\n    * Add --unselectable and --save-as-image options.\n    * Fix bug with temporary files on Windows.\n* 2.1.2\n    * Fix missing Poppler dependancy.\n    * Add test and lint to CI.\n* 2.2.0\n    * Support PDFs with pages of different sizes.\n* 2.2.1\n    * Support line breaks in text watermark.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Acknowledgments\n\n* [readme template](https://gist.github.com/DomPizzie/7a5ff55ffa9081f2de27c315f5018afc)\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) [2023] [Bastien Le Chenadec]  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A python CLI tool to add watermarks to a PDF",
    "version": "2.2.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/bastienlc/pdf-watermark/issues",
        "Homepage": "https://github.com/bastienlc/pdf-watermark",
        "Repository": "https://github.com/bastienlc/pdf-watermark.git"
    },
    "split_keywords": [
        "pdf",
        " watermark",
        " cli"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6bd0fd541ef8f1f88c7955f4d68a4b2cbcb0d0b1fe368e217903b6c3c6d514b2",
                "md5": "462a7362d6bcecebef621ef601b98a77",
                "sha256": "f6d697ca40920547f90bd52377dfd9173fb752c3ddaa5529619c395c567fbca8"
            },
            "downloads": -1,
            "filename": "pdf_watermark-2.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "462a7362d6bcecebef621ef601b98a77",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 13203,
            "upload_time": "2024-04-25T20:51:27",
            "upload_time_iso_8601": "2024-04-25T20:51:27.392230Z",
            "url": "https://files.pythonhosted.org/packages/6b/d0/fd541ef8f1f88c7955f4d68a4b2cbcb0d0b1fe368e217903b6c3c6d514b2/pdf_watermark-2.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "006ec6823684e7ebd7850a36f9c6a90138334ae3683a5c7ea0a3ebfb552177d9",
                "md5": "ead56a2b2ccd62ed7518fa78225ca2d7",
                "sha256": "6251c596993ee765b835222d25acc20771cb057baa7b7dcf03cf8bd06061c700"
            },
            "downloads": -1,
            "filename": "pdf_watermark-2.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ead56a2b2ccd62ed7518fa78225ca2d7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 868787,
            "upload_time": "2024-04-25T20:51:29",
            "upload_time_iso_8601": "2024-04-25T20:51:29.237099Z",
            "url": "https://files.pythonhosted.org/packages/00/6e/c6823684e7ebd7850a36f9c6a90138334ae3683a5c7ea0a3ebfb552177d9/pdf_watermark-2.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-25 20:51:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bastienlc",
    "github_project": "pdf-watermark",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pdf-watermark"
}
        
Elapsed time: 0.24701s