Python Programs

Convert TIFF To PDF In Python

Convert Tiff To PDF In Python

In this tutorial I will show you how to convert tiff to pdf in python programming so if you want to know how to convert a tiff file to pdf file in python then read till the end.

TIFF (Tagged Image File Format) it is used to store raster graphics and images. The key feature about this file format is the ability to handle wide variety of image types.

Install Pillow Library In Python

To do TIFF to PDF conversion using python I will use the pillow library which allows us to convert images to different types. It will allow us to convert tiff file to pdf with just 4 lines of python code and you can also use to convert other formats.

pip install Pillow

Copy and paste the above command in your terminal it will install the library. We have the library now let’s code.

Python Code To Convert TIFF To PDF File

from PIL import Image

with Image.open("test.tiff") as img:
    # Converts the tiff to rgb
    img = img.convert("RGB")
    img.save("output.pdf", "PDF")

Above is the code to convert a tiff file to pdf as you can see it is just 4 lines I will explain what each line does next but now you can test it by providing a example tiff file and running. After running it will create a ouput.pdf file in your folder.

In the first line we import the Image module from the pillow library, The second line opens the tiff file using the image module from pillow.

As you can see it converts tiff file to RGB before saving it to a pdf file it is necessary because it cannot save mode RGBA.

You will see it will create a pdf file in your folder. So this was the short tutorial on converting tiff file to pdf in python.

Here are some more python tutorials you might like:

I hope you found this tutorial helpful and useful do share it with someone who might need it. Want to stay updated with our latest tutorials then join our telegram channel.

Thanks for reading, Have a nice day 🙂