This article mainly describes the python combined with ImageMagick implementation of multiple images merged into a PDF file, combined with an example of Python to convert the image file to PDF file of the relevant operation skills, the need for friends can refer to the following
This example describes how Python combines ImageMagick to combine multiple images into a single PDF file. Share to everyone for your reference, as follows:
Some time ago bought a lot of books, and now the accumulation of more and more books, the Beijing side rented a small room more and more full of space. Ever since I got used to the gesture of a laptop touchpad, I thought I'd enjoy using my computer to read electronic documents. So I want to use some of his books to take pictures, and then merge into a PDF file.
Originally tried to look for mature Windows software, but never found a good software. Want to write script processing, has not been implemented. Accidentally view the description of the ImageMagick software and find a way to bulk merge. As a result, this feature is finally easy to implement.
Wrote a simple little script:
Import Osdefcompressimage (image_name): os.system ("convert-resize\" 600x800>\ "%s%s"% (image_name,image_name ) def compressall (): ext_names = ['. JPG ', '. jpg ', '. Jepg '] for each_image in Os.listdir ('./'): For ext_name in Ext_names: Ifeach_ Image.endswith (ext_name): compressimage (each_image) Breakcompressall () Os.system ("convert*. JPG book.pdf ")
After the script runs, a PDF file is generated. Open the file as follows:
From the above results can be seen, the image of the bulk of the synthesis of PDF file function is implemented. Naturally, you need to consider the sorting of files when crafting. Later check the rules of sorting to rename the file.
More readers interested in Python-related content can view the topic: "Python File and directory Operation skills Summary", "Python Coding skills Summary", "Python data structure and algorithm tutorial", "Python function Tips Summary", " Python string manipulation Tips summary and Python introductory and advanced classic tutorials