diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2020-02-26 16:37:09 +0000 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2020-02-26 16:37:09 +0000 |
| commit | 91cb0d496aadb56a547746cf7ff778a64cac7178 (patch) | |
| tree | d717ce5a4e1bdca13d375148b478927a606ceeb6 | |
| parent | Minor readme updates (diff) | |
| download | paper2remarkable-91cb0d496aadb56a547746cf7ff778a64cac7178.tar.gz paper2remarkable-91cb0d496aadb56a547746cf7ff778a64cac7178.zip | |
Only use shrunk file if it is indeed smaller
| -rw-r--r-- | paper2remarkable/pdf_ops.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/paper2remarkable/pdf_ops.py b/paper2remarkable/pdf_ops.py index 5e7e111..41cb85f 100644 --- a/paper2remarkable/pdf_ops.py +++ b/paper2remarkable/pdf_ops.py @@ -58,7 +58,8 @@ def blank_pdf(filepath): def shrink_pdf(filepath, gs_path="gs"): """Shrink the PDF file size using Ghostscript """ - logger.info("Shrinking pdf file") + logger.info("Shrinking pdf file ...") + size_before = os.path.getsize(filepath) output_file = os.path.splitext(filepath)[0] + "-shrink.pdf" status = subprocess.call( [ @@ -78,4 +79,8 @@ def shrink_pdf(filepath, gs_path="gs"): if not status == 0: logger.warning("Failed to shrink the pdf file") return filepath + size_after = os.path.getsize(output_file) + if size_after > size_before: + logger.info("Shrinking has no effect for this file, using original.") + return filepath return output_file |
