added report lab options
This commit is contained in:
@@ -4,6 +4,8 @@ from datetime import datetime, timedelta
|
||||
from flask import Blueprint, render_template, redirect, url_for, request, flash, session, current_app, jsonify
|
||||
from .models import User
|
||||
from . import db
|
||||
from reportlab.lib.pagesizes import letter
|
||||
from reportlab.pdfgen import canvas
|
||||
|
||||
bp = Blueprint('main', __name__)
|
||||
|
||||
@@ -61,7 +63,7 @@ def settings():
|
||||
# Load external database settings from the instance folder
|
||||
external_settings = {}
|
||||
settings_file = os.path.join(current_app.instance_path, 'external_server.conf')
|
||||
if os.path.exists(settings_file):
|
||||
if (os.path.exists(settings_file)):
|
||||
with open(settings_file, 'r') as f:
|
||||
for line in f:
|
||||
key, value = line.strip().split('=', 1)
|
||||
@@ -385,4 +387,37 @@ def save_template():
|
||||
data = request.get_json()
|
||||
# Replace with logic to save the template to the database
|
||||
print(f"Saving template: {data}")
|
||||
return jsonify({'message': 'Template saved successfully!'})
|
||||
return jsonify({'message': 'Template saved successfully!'})
|
||||
|
||||
@bp.route('/generate_pdf', methods=['POST'])
|
||||
def generate_pdf():
|
||||
data = request.get_json()
|
||||
width = data.get('width', 100) # Default width in mm
|
||||
height = data.get('height', 50) # Default height in mm
|
||||
columns = data.get('columns', [])
|
||||
|
||||
# Convert dimensions from mm to points (1 mm = 2.83465 points)
|
||||
width_points = width * 2.83465
|
||||
height_points = height * 2.83465
|
||||
|
||||
# Ensure the /static/label_templates folder exists
|
||||
label_templates_folder = os.path.join(current_app.root_path, 'static', 'label_templates')
|
||||
os.makedirs(label_templates_folder, exist_ok=True)
|
||||
|
||||
# Define the path for the PDF file
|
||||
pdf_file_path = os.path.join(label_templates_folder, 'label_template.pdf')
|
||||
|
||||
# Create a PDF file
|
||||
c = canvas.Canvas(pdf_file_path, pagesize=(width_points, height_points))
|
||||
|
||||
# Add content to the PDF
|
||||
c.drawString(10, height_points - 20, "Label Template")
|
||||
y_position = height_points - 40
|
||||
for column in columns:
|
||||
c.drawString(10, y_position, f"Column: {column}")
|
||||
y_position -= 20
|
||||
|
||||
# Save the PDF
|
||||
c.save()
|
||||
|
||||
return jsonify({'message': 'PDF generated successfully!', 'pdf_path': f'/static/label_templates/label_template.pdf'})
|
||||
Reference in New Issue
Block a user