File size: 604 Bytes
41265a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#import os
import requests
from pdf2image import convert_from_bytes

def download_pdf(url):
    response = requests.get(url)
    return response.content

def convert_pdf_to_images(pdf_bytes):
    images = convert_from_bytes(pdf_bytes)

    #if not os.path.exists(output_folder):
        #os.makedirs(output_folder)

    for i, image in enumerate(images):
        image.save(f'image{i}.png')

# Use the functions
#url = 'http://example.com/path_to_your_pdf.pdf'
#pdf_bytes = download_pdf(url)
#output_folder = os.environ.get('HUGGINGFACE_CACHE', 'images')
convert_pdf_to_images('hoor.pdf', output_folder)