from fpdf import FPDF
import glob
from fpdf.enums import XPos,YPos

A4W = 210
A4H = 297


pdf = FPDF()
pdf.add_page()
pdf.add_font('DejaVu','','DejaVuSans.ttf', uni=True)
pdf.set_font('DejaVu', size = 12)
pdf.cell(text="Oferta biura podróży")

pdf.image("download.jpeg", x= A4W * 0.25, y=A4W * 0.25, w=A4W * 0.5, h = A4W * 0.5)

pdf.set_font('DejaVu', size=32)
pdf.text(x=40, y=A4W *0.75 + 30, text = "Wycieczki:")
pdf.set_font('DejaVu', size=10)
pdf.text(x=120, y=A4W* 1.1 +50, text = "Wygenerowano przy pomocy pythona i Ai")

for image_path in glob.glob("zdjecia/*"):
    print(image_path)

    atraction = image_path[:-5].replace("zdjecia\\","")
    print(atraction)
    
    text_path = f"te/{atraction}.txt"


    pdf.add_page()

    pdf.set_font("DejaVu",size = 24)

    pdf.cell(200, 20, text=f"Nazwa miejsca docelowego: {atraction.capitalize()}",
             new_x = XPos.LEFT, new_y= YPos.NEXT, aling="C")


    pdf.cell(200, 10, link=pdf.image(f"{image_path}", w = 195, h = 120),
            new_x = XPos.LEFT, new_y= YPos.NEXT, aling="C")


with open(text_path, "r", encoding="utf-8") as file:
    pass

pdf.output("Oferta.pdf") 