import os
from reportlab.lib.pagesizes import A4, landscape
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image, Table, TableStyle, HRFlowable
from reportlab.lib.units import cm

pdf_path = "/home/magdalena/eee/alunos/rafael-rosa-batista/Plano_de_Linhas_2D_Saveiro_Ciclone_2.pdf"

doc = SimpleDocTemplate(
    pdf_path,
    pagesize=landscape(A4),
    leftMargin=1.5*cm,
    rightMargin=1.5*cm,
    topMargin=1.2*cm,
    bottomMargin=1.2*cm
)

styles = getSampleStyleSheet()

primary_color = colors.HexColor("#1A365D")
secondary_color = colors.HexColor("#2B6CB0")

title_style = ParagraphStyle(
    'DocTitle',
    parent=styles['Normal'],
    fontName='Helvetica-Bold',
    fontSize=15,
    leading=18,
    textColor=primary_color,
    spaceAfter=2
)

subtitle_style = ParagraphStyle(
    'DocSubTitle',
    parent=styles['Normal'],
    fontName='Helvetica',
    fontSize=9.5,
    leading=12,
    textColor=secondary_color,
    spaceAfter=6
)

story = []
story.append(Paragraph("PLANO DE LINHAS 2D & TABELA DE COTAS: SAVEIRO CICLONE 2 (7,0 M)", title_style))
story.append(Paragraph("<b>Digitalização e Análise do Croqui Técnico em Papel Quadriculado (Balizas 0 a 7)</b><br/><b>Aluno / Projetista:</b> Rafael Rosa Batista | <b>Orientação:</b> Profa. Magdalena (Mada) - Brana / EEE", subtitle_style))
story.append(HRFlowable(width="100%", thickness=1.2, color=secondary_color, spaceBefore=0, spaceAfter=6))

img_path = "/home/magdalena/eee/alunos/rafael-rosa-batista/Rascunho_2D_Plano_Linhas_Saveiro_Ciclone_2.png"
if os.path.exists(img_path):
    # Landscape A4 usable width is ~26.7cm, height is ~17.5cm
    story.append(Image(img_path, width=26.0*cm, height=14.5*cm))

doc.build(story)
print("PDF Plano de Linhas 2D built at:", pdf_path)
