diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-07-13 01:15:46 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-07-22 00:36:24 +0200 |
| commit | 2f2df8e53124bee8bc8312f37bc8608dc46085d6 (patch) | |
| tree | 820157a6294115fe0b4bbb0d41ef3526cf20e2f0 /doc/manual/pdf_crop_by.py | |
| parent | 95fc64295a860814ddee477c46e2028ea1a1f15c (diff) | |
Use PDF screenshots for the manual.
Diffstat (limited to 'doc/manual/pdf_crop_by.py')
| -rw-r--r-- | doc/manual/pdf_crop_by.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/doc/manual/pdf_crop_by.py b/doc/manual/pdf_crop_by.py new file mode 100644 index 000000000..ccc6d370d --- /dev/null +++ b/doc/manual/pdf_crop_by.py @@ -0,0 +1,27 @@ +import shlex +import subprocess +import sys + +if len(sys.argv) != 7: + print("Syntax: %s <in-pdf> <out-pdf> <left> <bottom> <right> <top>" % sys.argv[0]) + sys.exit(1) + +in_pdf = sys.argv[1] +out_pdf = sys.argv[2] + +cp = subprocess.run(shlex.split('gs -dNOPAUSE -dBATCH -sDEVICE=bbox %s' % in_pdf), capture_output=True) +if cp.returncode != 0: + print("gs call failed", file=sys.stderr) + sys.exit(1) +for line in cp.stderr.splitlines(): + print(line) + if line.startswith(b"%%BoundingBox"): + old_bbox = line.split()[1:] + new_bbox = [] + for i in range(0, 2): + new_bbox.append(int(old_bbox[i]) + int(sys.argv[i+3])) + for i in range(2, 4): + new_bbox.append(int(old_bbox[i]) - int(sys.argv[i+3])) + print(new_bbox) + cp = subprocess.run(shlex.split('pdfcrop --bbox "%d %d %d %d" %s %s' % (new_bbox[0], new_bbox[1], new_bbox[2], new_bbox[3], in_pdf, out_pdf))) + |
