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/Rascunho_2D_Saveiro_Ciclone_2_Consolidado.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("PROJETO NAVAL 2D CONSOLIDADO: SAVEIRO CICLONE 2 (7,0 M)", title_style))
story.append(Paragraph("<b>Plano de Perfil, Planta com Corpo Paralelo e Plano de Balizas com $C_M = 0,78$</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_Saveiro_Ciclone_2_Consolidado.png"
if os.path.exists(img_path):
    story.append(Image(img_path, width=26.0*cm, height=14.5*cm))

doc.build(story)
print("Consolidated PDF generated at:", pdf_path)
