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_Secao_Mestra_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("RASCUNHO TÉCNICO 2D: SEÇÃO MESTRA & COEFICIENTE $C_M = 0,78$", title_style))
story.append(Paragraph("<b>Digitalização e Análise Naval da Seção Transversal e Bojo Arredondado</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_Secao_Mestra_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 Rascunho 2D Seção Mestra built successfully at:", pdf_path)
