pdfebc - PDF ebook compressor
Overview
pdfebc is a CLI tool that uses Ghostscript to compress PDF documents to a size that befits an ebook reader, such as a Kindle. The CLI works by targeting a source and output directory (if not specified by the user, defults to use . for source and pdfebc_out for output), and then compresses all PDF files in the source directory and puts the results in the output directory. There is also functionality for sending the compressed documents to a pre-configured e-mail address using Google’s SMTP server (which can easily be swapped for any SMTP server by editing the source code, see Requirements below). Files that are less than 1 MB in size are not compressed, as I have found that compressing such small files often leads to them increasing in size several times over instead (I have yet to figure out why). Do note that Ghostscript is fairly slow, so expect large files to take a while to compress.
As an example use case, I mainly use pdfebc as an easy way to compress lecture slides and similar study materials, send them to my Kindle and then clean up the output.
Purpose of the project
The core functionality of pdfebc was already done when I started this little project. As such, the main purpose here isn’t to provide the functionality, but to do so in a robust way, with proper documentation, testing and continuous integration. It is, essentially, my first foray into using stuff like sphinx, Travis-CI and ReadTheDocs, so there’s bound to be some weirdness here and there. I am also diving deeper into how to use git and trying new things, so the commit history is a bit inconsistent.
Requirements
- Python 3.6
Strictly speaking, 3.5 should also work fine, but the tests use 3.6 features so the build is only tested for 3.6.
- Ghostscript
pdfebc requires Ghostscript for the PDF compression. The default binary is gs, but this can be specified via the CLI.
- A Gmail account (for sending e-mails)
By default, pdfebc uses Google’s SMTP server to send e-mails. If you don’t intend to use the send functionality, then you may disregard this requirement.
It is possible to use a different SMTP server by changing the SMTP_SERVER variable in the pdfebc.utils module. Note that TLS is enabled and will likely cause sending e-mails using a local server that does not have TLS impossible.
Install
Option 1: Install from PyPi with pip
The latest release of pdfebc is on PyPi, and can thus be installed as usual with pip. I strongly discourage global pip installs (i.e. sudo pip install <package>), as this may land you with incompatible packages in a very short amount of time. A per-user install can be done like this:
Execute pip install --user pdfebc to install the package.
- Type echo "$PATH" and verify that $HOME/.local/bin is on the PATH.
If it is not, add it by adding export PATH="$PATH:$HOME/.local/bin to your shell configuration file (e.g. $HOME/.bashrc for bash).
Then execute source <path_to_config_file>
Currently, you must add the configuration file manually. Please have a look at the sample configuration file for details. To find out where to place the file, run pdfebc -h. This should cause a message to appear, telling you where to put the file. This lazy way of handling the setup of the configuration will be replaced with a step-by-step config creator in version 0.3.0. Note: When using a Gmail account, I strongly recommend using an App password instead of the actual account password.
Verify the installation by executing pdfebc -h. You should see usage information printed to stdout, with no errors.
Option 2: Clone the repo and the install with pip
If you want the dev version, you will need to clone the repo, as only release versions are uploaded to PyPi. Unless you are planning to work on this yourself, I suggest going with the release version.
- Clone the repo with git:
git clone https://github.com/slarse/pdfebc
- cd into the project root directory and install with pip.
pip install --user ., global installs are not recommended.
Or just pip install . if you use virtualenv.
For development, use pip install -e . in a virtualenv.
Currently, you must add the configuration file manually. Please have a look at the sample configuration file for details. To find out where to place the file, run pdfebc -h. This should cause a message to appear, telling you where to put the file. This lazy way of handling the setup of the configuration will be replaced with a step-by-step config creator in version 0.3.0. Note: When using a Gmail account, I strongly recommend using an App password instead of the actual account password.
Verify the installation by executing pdfebc -h. You should see usage information printed to stdout, with no errors.
License
This software is licensed under the MIT License. See the license file file for specifics.
Contributing
I am currently not looking for contributions. At this point, this is a practice project for me, and even if I were looking for outside help the test suite is nowhere near comprehensive enough for that yet. Sorry!
TODO
Improve code coverage.
Add more negative tests.
Metadata
Release files for pdfebc 0.2.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 | Provenance | Actions |
|---|---|---|---|---|
| pdfebc-0.2.0.tar.gz | 14.7 kB | Without provenance | Details for pdfebc-0.2.0.tar.gz |
Release files / pdfebc-0.2.0.tar.gz
| Download URL | pdfebc-0.2.0.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7032105d25bb8a5d84fd694d4630a8d3c174ce9a860d70386d5c382eee60add9
|
|
BLAKE2b-256 checksum How to use checksums |
640734dbeaca5bc2cc9c3fd81b6a1248029428711f7f17d7bd90f86bace1099e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pdfebc 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.