modified: .gitignore

modified:   QUICKSTART.md
	modified:   app.py
	new file:   output/.gitkeep
	modified:   static/css/style.css
	modified:   static/js/images-to-pdf.js
	modified:   templates/images_to_pdf.html
	new file:   uploads/.gitkeep
This commit is contained in:
SimolZimol
2025-10-12 22:39:04 +02:00
parent 97fd0762d7
commit a01a5c1274
8 changed files with 313 additions and 28 deletions

41
app.py
View File

@@ -112,9 +112,9 @@ def convert_images_to_pdf():
"""Konvertiert hochgeladene Bilder zu PDF"""
try:
data = request.get_json()
filenames = data.get('filenames', [])
files_data = data.get('files', [])
if not filenames:
if not files_data:
return jsonify({'error': 'Keine Dateien ausgewählt'}), 400
# PDF erstellen
@@ -125,12 +125,19 @@ def convert_images_to_pdf():
c = canvas.Canvas(output_path, pagesize=A4)
page_width, page_height = A4
for filename in filenames:
for file_data in files_data:
filename = file_data.get('filename')
rotation = file_data.get('rotation', 0)
file_path = os.path.join(UPLOAD_FOLDER, filename)
if os.path.exists(file_path):
# Bild öffnen und Größe anpassen
# Bild öffnen und rotieren
with Image.open(file_path) as img:
# Bild rotieren falls nötig
if rotation != 0:
img = img.rotate(-rotation, expand=True) # Negative Rotation für korrekte Richtung
img_width, img_height = img.size
# Seitenverhältnis berechnen
@@ -151,8 +158,16 @@ def convert_images_to_pdf():
x = (page_width - new_width) / 2
y = (page_height - new_height) / 2
# Bild zur PDF hinzufügen
c.drawImage(file_path, x, y, width=new_width, height=new_height)
# Temporäres rotiertes Bild speichern
if rotation != 0:
temp_path = os.path.join(UPLOAD_FOLDER, f"temp_rotated_{filename}")
img.save(temp_path)
c.drawImage(temp_path, x, y, width=new_width, height=new_height)
# Temporäre Datei löschen
os.remove(temp_path)
else:
c.drawImage(file_path, x, y, width=new_width, height=new_height)
c.showPage()
c.save()
@@ -278,6 +293,20 @@ def merge_pdfs():
except Exception as e:
return jsonify({'error': f'Fehler beim Zusammenführen: {str(e)}'}), 500
@app.route('/uploads/<filename>')
def serve_uploaded_file(filename):
"""Serviert hochgeladene Dateien für die Vorschau"""
try:
file_path = os.path.join(UPLOAD_FOLDER, filename)
if not os.path.exists(file_path):
return "Datei nicht gefunden", 404
return send_file(file_path)
except Exception as e:
return f"Fehler beim Laden der Datei: {str(e)}", 500
@app.route('/download/<filename>')
def download_file(filename):
"""Download einer generierten Datei"""