Thursday 16 March 2023

How to download files from Slide share

 1. Go to the slideshare and inspect the source and get the link and use the following code in python 

import urllib.request

# URL of the image to be downloaded
# Loop over a range of numbers with a different starting and ending value
for i in range(1, 311):
   url = 'https://image.slidesharecdn.com/an14v1consar-160210214304/75/annex-14-icao-arabic-version-'+str(i)+'-2048.jpg'
   filename = str(i)+'.jpg'
   urllib.request.urlretrieve(url, filename)



Convert the images to pdf using the following code 


from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from PIL import Image

# List of image filenames to combine
image_files =[]
for i in range(1, 311):
   image_files.append(str(i)+'.jpg')

# Create a new PDF file
pdf_file = canvas.Canvas('images.pdf', pagesize=letter)


# Loop over the image files and add them to the PDF
for image_file in image_files:
    # Open the image file using PIL
    image = Image.open(image_file)

    # Calculate the aspect ratio of the image
    width, height = image.size
    aspect_ratio = height / width

    # Add the image to the PDF
    pdf_file.setPageSize((letter[0], letter[0] * aspect_ratio))
    pdf_file.drawImage(image_file, 0, 0, letter[0], letter[0] * aspect_ratio)

    # Add a new page to the PDF for the next image
    pdf_file.showPage()

# Save the PDF file
pdf_file.save()