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_e_Hidrostatica_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, GEOMETRIA E HIDROSTÁTICA: SAVEIRO CICLONE 2 (7,0 M)", title_style))
story.append(Paragraph("<b>Integração do Perfil Tradicional (Roda de Proa/Tosamento) e Seção Mestra ($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/Plano_Linhas_Completo_Saveiro_Ciclone_2.png"
if os.path.exists(img_path):
    story.append(Image(img_path, width=26.0*cm, height=14.5*cm))

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