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_Oficial_Saveiro_Ciclone_2_Calado_350mm.pdf"

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

styles = getSampleStyleSheet()

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

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

subtitle_style = ParagraphStyle(
    'DocSubTitle',
    parent=styles['Normal'],
    fontName='Helvetica',
    fontSize=9,
    leading=11.5,
    textColor=secondary_color,
    spaceAfter=4
)

story = []
story.append(Paragraph("PLANO DE LINHAS OFICIAL: SAVEIRO CICLONE 2 (7,00 M)", title_style))
story.append(Paragraph("<b>Calado de Projeto: 350 mm (DWL) | Inclinação do Espelho de Popa: 20° | Tabela de Cotas Oficial (7 Balizas)</b><br/><b>Projetista:</b> Rafael Rosa Batista | <b>Orientação:</b> Profa. Magdalena (Mada) - Brana / EEE | <b>Grupo:</b> Grupo 8", subtitle_style))
story.append(HRFlowable(width="100%", thickness=1.2, color=secondary_color, spaceBefore=0, spaceAfter=4))

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

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