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("logo.jpeg", x = A4W * 0.25, y=A4W * 0.25,
          w=A4W * 0.5, h=A4W * 0.5)


pdf.set_font('DejaVu', size=32)
pdf.set_text_color(255,0,0)
pdf.text(x=40, y=A4W *0.75+30, text = "Wycieczki:")

pdf.set_font('DejaVu', size=8)
pdf.set_text_color(0,0,0)

pdf.text(x=140, y=A4H-30, 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"opisy/{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, align="C")

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

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

pdf.output("Oferta.pdf")