Thursday, January 19, 2017

Add Multiple map images into one PDF file per page

Bulk images to pdf Tutorial

In this post I will show you how to create an atlas like of Nigeria LGA maps. Let me explain better by using the map of Abuja as an example.

This is a simple script procedure to collect images from a folder and add into a pdf file with each per page.



Abuja (FCT) has six municipal area councils that is the equivalent of LGA for other states. Now I want to create a pdf file to contain or display the map of Abuja and the six municipal area councils with each map on a new page.

This task could be done manually, but since I intend to do the same for all the states, that is about 700+ maps for the whole LGAs. The process become tedious to accomplished, so I use python pdf package (called reportlab) to automate the process as follow.

The maps above are to be added to a single pdf file with each map on a new page. I use python glob module to read in the map images, use for loop to iterate the files and used python reportlab module to generate the pdf file.

The final code is as seen below:-


Note: the above script was written and tested on Python 2. You will need to modify some lines to run/use it with Python 3.

The resulting pdf and other files used for the script are here.


That is it!

No comments:

Post a Comment