From b3a9474e4e91fb2e5999b5dc80509638e68dcf1d Mon Sep 17 00:00:00 2001 From: Axel Svensson Date: Sun, 8 Sep 2024 04:53:21 +0200 Subject: [PATCH] Fix: Account for imprecision in ghostscript Fixes #14. --- pdf-sign | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pdf-sign b/pdf-sign index 9f6b9d7..f0e9e5b 100755 --- a/pdf-sign +++ b/pdf-sign @@ -130,6 +130,8 @@ def main(args): cache = translatablePDF._cache if path not in cache: (w, h) = pdfGetSize(path) + if not (1 < w and 1 < h): + die(f"The PDF at {path} is unusable as a signature due to too small dimensions.") (double_w, double_h) = (2*w, 2*h) testFile = intmp('translateTest.pdf') subprocess.run([ @@ -141,7 +143,7 @@ def main(args): '-f', path, ], check=True) (test_w, test_h) = pdfGetSize(testFile) - if (test_w, test_h) == (double_w, double_h): + if abs(test_w - double_w) < 0.01 and abs(test_h - double_h) < 0.01: # The pdf file at path can be translated correctly cache[path] = path elif (test_w, test_h) == (w, h):