''' Summing pages. '''
from fpdf import FPDF
from PIL import Image
from PIL import Image, ImageOps


''' Create FPDF object. '''

pdf = FPDF('L', 'mm', format='A4') # 148 × 210
pdf_height = 210
pdf.set_margin(0)

''' Load image. '''
# Open image and get height.
img = Image.open('drawng/IMG_1069.jpg')
width, height = img.size

# Define iterations:
iterations = 20
# Step for image:
step = width / iterations # Step = amount of pixels to reveal in one iteration.


''' Loop. '''
for i in range(1, iterations + 1):
    pdf.add_page()


    bordered = ImageOps.expand(img, border=30, fill=(0,0,0))
    bordered = bordered.crop((0, 0, step * i, height))
    bordered.save(f'temp{i}.png' )





    pdf.image(f'temp{i}.png', x = 0, y = 0, h = pdf_height+1)



''' Save PDF. '''

pdf.output('16.pdf')
        

Book by Parisa Zaeri

I always wanted to turn some of my digital drawings from a particular object (which were done by different brushes) into a book in a way that they make the viewer want to know what the next page would look like, just like the way good authors make us anticipate the next page of their books. For this project, I've written a simple code with Python to make a PDF out of my simple sketches of a Bonsai. With this code, the sketches are displayed step by step, one after the other, in the form of a PDF file. This is the magic of crop function!

Download PDF.