diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-05-31 22:20:53 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-05-31 22:20:53 +0100 |
| commit | 16d38638d6f5a9bd4ab9534f5ce3c744744e7aef (patch) | |
| tree | 48838d8e4426ec3a670f38b17240203fc15a8323 | |
| parent | Merge branch 'master' into center_pdf (diff) | |
| parent | bump version and update readme (diff) | |
| download | paper2remarkable-16d38638d6f5a9bd4ab9534f5ce3c744744e7aef.tar.gz paper2remarkable-16d38638d6f5a9bd4ab9534f5ce3c744744e7aef.zip | |
Merge branch 'master' into center_pdf
| -rw-r--r-- | README.md | 19 | ||||
| -rwxr-xr-x | arxiv2remarkable.py | 28 |
2 files changed, 39 insertions, 8 deletions
@@ -15,18 +15,21 @@ The script takes the source and: 2. Removes the arXiv timestamp 3. Crops the pdf to remove unnecessary borders 4. Shrinks the pdf file to reduce the filesize -5. Generates a nice filename based on author/title/year of the paper (arXiv - only) +5. Generates a nice filename based on author/title/year of the paper 6. Uploads it to your reMarkable using ``rMapi``. -Optionally, you can download a paper but not have it uploaded to the -reMarkable using the ``-n`` switch. Also, the ``--filename`` parameter to the -script can be used to provide an explicit filename for on the reMarkable. +Optionally, you can: + +- Download a paper but not upload to the reMarkable using the ``-n`` switch. +- Insert a blank page after each page using the ``-b`` switch (useful for note + taking!) +- Provide an explicit filename using the ``--filename`` parameter +- Specify the location on the reMarkable to place the file (default ``/``) Here's the full help of the script: ```text -usage: arxiv2remarkable.py [-h] [-v] [-n] [-d] [--filename FILENAME] +usage: arxiv2remarkable.py [-h] [-b] [-v] [-n] [-d] [--filename FILENAME] [-p REMARKABLE_DIR] [--rmapi RMAPI] [--pdfcrop PDFCROP] [--pdftk PDFTK] [--gs GS] input @@ -37,6 +40,8 @@ positional arguments: optional arguments: -h, --help show this help message and exit + -b, --blank Add a blank page after every page of the PDF (default: + False) -v, --verbose be verbose (default: False) -n, --no-upload don't upload to the reMarkable, save the output in current working dir (default: False) @@ -54,7 +59,7 @@ optional arguments: ``` And here's an example with verbose mode enabled that shows everything the -script does: +script does by default: ```bash $ python arxiv2remarkable.py -v https://arxiv.org/abs/1811.11242 diff --git a/arxiv2remarkable.py b/arxiv2remarkable.py index 3994b1b..4f36c66 100755 --- a/arxiv2remarkable.py +++ b/arxiv2remarkable.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -__version__ = "0.2.0" +__version__ = "0.2.1" __author__ = "G.J.J. van den Burg" """ @@ -50,6 +50,7 @@ class Provider(metaclass=abc.ABCMeta): upload=True, debug=False, center=False, + blank=False, remarkable_dir="/", rmapi_path="rmapi", pdfcrop_path="pdfcrop", @@ -60,6 +61,7 @@ class Provider(metaclass=abc.ABCMeta): self.upload = upload self.debug = debug self.center = center + self.blank = blank self.remarkable_dir = remarkable_dir self.rmapi_path = rmapi_path self.pdfcrop_path = pdfcrop_path @@ -147,6 +149,22 @@ class Provider(metaclass=abc.ABCMeta): return filepath return centered_file + def blank_pdf(self, filepath): + if not self.blank: + return filepath + + self.log("Adding blank pages") + input_pdf = PyPDF2.PdfFileReader(filepath) + output_pdf = PyPDF2.PdfFileWriter() + for page in input_pdf.pages: + output_pdf.addPage(page) + output_pdf.addBlankPage() + + output_file = os.path.splitext(filepath)[0] + "-blank.pdf" + with open(output_file, "wb") as fp: + output_pdf.write(fp) + return output_file + def crop_pdf(self, filepath): self.log("Cropping pdf file") status = subprocess.call( @@ -300,6 +318,7 @@ class Provider(metaclass=abc.ABCMeta): self.dearxiv, self.crop_pdf, self.center_pdf, + self.blank_pdf, self.shrink_pdf, ] intermediate_fname = tmp_filename @@ -548,6 +567,12 @@ def parse_args(): formatter_class=argparse.ArgumentDefaultsHelpFormatter ) parser.add_argument( + "-b", + "--blank", + help="Add a blank page after every page of the PDF", + action="store_true", + ) + parser.add_argument( "-v", "--verbose", help="be verbose", action="store_true" ) parser.add_argument( @@ -616,6 +641,7 @@ def main(): upload=not args.no_upload, debug=args.debug, center=args.center, + blank=args.blank, remarkable_dir=args.remarkable_dir, rmapi_path=args.rmapi, pdfcrop_path=args.pdfcrop, |
