From ad7a043b2f07bfbe28ea30e8a51bc616bc01f28a Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Fri, 31 May 2019 22:09:11 +0100 Subject: add support for adding blank pages --- arxiv2remarkable.py | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/arxiv2remarkable.py b/arxiv2remarkable.py index 08beaca..bedfc7e 100755 --- a/arxiv2remarkable.py +++ b/arxiv2remarkable.py @@ -46,6 +46,7 @@ class Provider(metaclass=abc.ABCMeta): verbose=False, upload=True, debug=False, + blank=False, remarkable_dir="/", rmapi_path="rmapi", pdfcrop_path="pdfcrop", @@ -55,6 +56,7 @@ class Provider(metaclass=abc.ABCMeta): self.verbose = verbose self.upload = upload self.debug = debug + self.blank = blank self.remarkable_dir = remarkable_dir self.rmapi_path = rmapi_path self.pdfcrop_path = pdfcrop_path @@ -111,6 +113,22 @@ class Provider(metaclass=abc.ABCMeta): self.log("Created filename: %s" % name) return name + 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( @@ -260,7 +278,12 @@ class Provider(metaclass=abc.ABCMeta): self.retrieve_pdf(src, tmp_filename) self.check_file_is_pdf(tmp_filename) - ops = [self.dearxiv, self.crop_pdf, self.shrink_pdf] + ops = [ + self.dearxiv, + self.crop_pdf, + self.blank_pdf, + self.shrink_pdf, + ] intermediate_fname = tmp_filename for op in ops: intermediate_fname = op(intermediate_fname) @@ -506,6 +529,12 @@ def parse_args(): parser = argparse.ArgumentParser( 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" ) @@ -565,14 +594,15 @@ def main(): exception("Input not valid, no provider can handle this source.") prov = provider( - args.verbose, - not args.no_upload, - args.debug, - args.remarkable_dir, - args.rmapi, - args.pdfcrop, - args.pdftk, - args.gs, + verbose=args.verbose, + upload=not args.no_upload, + debug=args.debug, + blank=args.blank, + remarkable_dir=args.remarkable_dir, + rmapi_path=args.rmapi, + pdfcrop_path=args.pdfcrop, + pdftk_path=args.pdftk, + gs_path=args.gs, ) prov.run(args.input, filename=args.filename) -- cgit v1.2.3 From abfeb4d4d55225babb5d70a273f4d931bcf043b7 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Fri, 31 May 2019 22:13:15 +0100 Subject: bump version and update readme --- README.md | 19 ++++++++++++------- arxiv2remarkable.py | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2de6ff8..6af087a 100644 --- a/README.md +++ b/README.md @@ -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 bedfc7e..9dcc1df 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" """ -- cgit v1.2.3