OEWE

PHOTO EMBED

Tue Dec 05 2023 11:20:42 GMT+0000 (Coordinated Universal Time)

Saved by @maltaellll

from pdf2image import convert_from_path
from PIL import Image
import os

def pdf_to_html_with_images(pdf_path):
    output_folder = os.path.dirname(pdf_path)
    images = convert_from_path(pdf_path)

    html_path = os.path.join(output_folder, 'output.html')
    
    with open(html_path, 'w', encoding='utf-8') as html_file:
        html_file.write('<!DOCTYPE html>\n<html>\n<body>\n')

        for i, image in enumerate(images):
            image_path = os.path.join(output_folder, f'image_{i}.png')
            image.save(image_path, 'PNG')
            html_file.write(f'<img src="{os.path.basename(image_path)}" alt="Image {i+1}"><br>\n')

        html_file.write('</body>\n</html>')

    return html_path

pdf_path = 'image-based-pdf-sample.pdf'  # Замените на путь к вашему PDF-файлу
generated_html = pdf_to_html_with_images(pdf_path)
print(f'HTML файл сохранен по пути: {generated_html}')
content_copyCOPY