|
|
from io import BytesIO |
|
|
from reportlab.lib.pagesizes import letter |
|
|
from reportlab.pdfgen import canvas |
|
|
from reportlab.lib import colors |
|
|
from reportlab.lib.styles import getSampleStyleSheet |
|
|
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle |
|
|
from convertion import convert_feet_to_inches,convert_inches_to_feet |
|
|
from convertion import convert_meters_to_unit, convert_to_meters |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def calculate_reduced_dimensions(width, height, unit, selection, object_item_value, item_type="Door"): |
|
|
|
|
|
if unit == 'Feet': |
|
|
reduction_width = convert_inches_to_feet(object_item_value[selection][item_type]['width']) |
|
|
reduction_height = convert_inches_to_feet(object_item_value[selection][item_type]['height']) |
|
|
else: |
|
|
reduction_width = object_item_value[selection][item_type]['width'] |
|
|
reduction_height = object_item_value[selection][item_type]['height'] |
|
|
selection_div = "divider_sh" if selection == 'shutter' else 'divider_gl' |
|
|
divider_h = object_item_value[selection_div][item_type]['height'] |
|
|
divider_w = object_item_value[selection_div][item_type]['width'] |
|
|
|
|
|
|
|
|
reduced_width = (width - reduction_width) / divider_w |
|
|
reduced_height = (height - reduction_height) / divider_h |
|
|
area,_ = calculate_area_and_frame(reduced_width,reduced_height,unit,item_type=item_type) |
|
|
return reduced_width, reduced_height, area |
|
|
|
|
|
|
|
|
def calculate_area_and_frame(width, height, unit, item_type="Door"): |
|
|
|
|
|
if unit == 'Inches': |
|
|
width = convert_inches_to_feet(width) |
|
|
height = convert_inches_to_feet(height) |
|
|
|
|
|
area = width * height |
|
|
frame_thickness = {'Door': 0.1, 'Window': 0.05} |
|
|
frame_area = 2 * (width + height) * frame_thickness.get(item_type, 0.1) |
|
|
|
|
|
return area, frame_area |
|
|
|
|
|
def generate_pdf(df_combined, company_name, address, unit): |
|
|
buffer = BytesIO() |
|
|
|
|
|
|
|
|
c = canvas.Canvas(buffer, pagesize=letter) |
|
|
width, height = letter |
|
|
|
|
|
y_position = height - 40 |
|
|
|
|
|
c.setFont("Helvetica", 12) |
|
|
c.drawString(30, y_position, f"Company Name: {company_name}") |
|
|
y_position -= 20 |
|
|
c.drawString(30, y_position, f"Address: {address}") |
|
|
|
|
|
|
|
|
y_position -= 10 |
|
|
c.setStrokeColor(colors.black) |
|
|
c.setLineWidth(1) |
|
|
c.line(30, y_position, width - 30, y_position) |
|
|
|
|
|
|
|
|
y_position -= 30 |
|
|
c.setFont("Helvetica-Bold", 16) |
|
|
c.drawString(30, y_position, f"Dimensions Calculation Results: for units ({unit})") |
|
|
|
|
|
|
|
|
y_position -= 20 |
|
|
|
|
|
|
|
|
data = [["Sl no", "Type", "Outer Frame", "Shutter", "Glass", "Area"]] |
|
|
for index, row in df_combined.iterrows(): |
|
|
data.append([row['Sl no'], row['Type'], row['Outer Frame'], row['Shutter'], row['Glass'], row['Area']]) |
|
|
|
|
|
|
|
|
row_height = 30 |
|
|
table = Table(data, colWidths=[50, 100, 100, 100, 100, 100], rowHeights=row_height) |
|
|
table.setStyle(TableStyle([ |
|
|
('TEXTCOLOR', (0, 0), (-1, 0), (0, 0, 0)), |
|
|
('ALIGN', (0, 0), (-1, -1), 'CENTER'), |
|
|
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'), |
|
|
('BOTTOMPADDING', (0, 0), (-1, 0), 12), |
|
|
('BACKGROUND', (0, 0), (-1, 0), (0.7, 0.7, 0.7)), |
|
|
('GRID', (0, 0), (-1, -1), 0.5, (0, 0, 0)) |
|
|
])) |
|
|
|
|
|
|
|
|
table.wrapOn(c, width, height) |
|
|
table.drawOn(c, 30, y_position-(len(df_combined)+1)*row_height) |
|
|
|
|
|
|
|
|
c.save() |
|
|
|
|
|
buffer.seek(0) |
|
|
return buffer |
|
|
|
|
|
|