Giter Site home page Giter Site logo

gallicality's Issues

Pour relier les images dans un PDF.

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()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.