Python combined with ImageMagick to implement multiple images merged into one PDF file method

Source: Internet
Author: User
Tags imagemagick
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.