-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Si cela peut aider...
#!/usr/bin/env python3
#
# Usage:
# pdf_stitch.py [-d] -o output.pdf -i input_folder
#
# Example
# pdf_stitch.py [-d] -o book.pdf -i "pages/*.jpg"
#
import sys, traceback, argparse, glob, img2pdf
from pathlib import Path
def parse_arguments():
"""
Purpose: parse all arguments and set as global args
"""
parser = argparse.ArgumentParser("Make a PDF out of a number of images [f1.img...fn.img] ")
parser.add_argument('-d', '--debug', help='debug flag', dest='debug', action='store_true', default=False)
parser.add_argument('-o', '--output', help='output PDF document', dest="output", required=True)
parser.add_argument('-i', '--input', help='input folder', dest="input", required=True)
return parser.parse_args()
def main():
"""
The main sequence of calls
:return: 0 if success
"""
args = parse_arguments()
try:
all_images = glob.glob(args.input)
all_images.sort(key=lambda x: int(Path(x).stem[1:]))
with open(args.output, "wb") as f:
f.write(img2pdf.convert(all_images))
except Exception as e:
traceback.print_exc()
success = False
else:
print(f"Successfully created book {args.output}")
success = True
sys.exit(1 if not success else 0)
if __name__ == '__main__':
main()
Metadata
Metadata
Assignees
Labels
No labels