![]() Next, we’ll need to loop over the folder content: 1 #. Īs mentioned earlier, we’ll start with a simple code, make it work, and abstract it later to some utility functions. 1 from PIL import Image 2 3 prefix = "" 4 min_range = 0 5 max_range = 3 6 suffix = ".png" 7 out_fname = "out.pdf" 8 9 #. The prefix is optional and could include the path to the folder if you want to keep your Python program outside of the image folder. Let’s start simple, say that you have a folder with some images that are named for example 0.png, 1.png, … Every file name has an optional prefix, an order number and a suffix that corresponds to the image type. If you need to install the two libraries, you could use pip, e.g.: 1 python -m pip install Pillow 2 python -m pip install img2pdf While there are many libraries that could be used for the above, in this post I will consider only two libraries Pillow, formerly named PIL and img2pdf. This is a problem that I encountered recently when I had to process a bunch of scanned images and save the processed files as a single PDF. ![]() ![]() ![]() In this article I will show you how to batch convert a folder with images to a PDF file. Solarian Programmer My programming ramblings Home Archives Contact Privacy Batch convert images to PDF with Python by using Pillow or img2pdf Posted on Jby Paul
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |