PDF: Font vor Firmendaten setzen, feste Position unter Logo (logo_bottom=50)
This commit is contained in:
39
app.py
39
app.py
@@ -6,7 +6,6 @@ Bietet eine Weboberflaeche zur Eingabe von Druckparametern,
|
||||
Live-Berechnung der Kosten, PDF-Rechnung und TXT-Export.
|
||||
"""
|
||||
import os
|
||||
import struct
|
||||
import yaml
|
||||
import io
|
||||
from datetime import datetime
|
||||
@@ -17,33 +16,6 @@ app = Flask(__name__)
|
||||
app.config['MAX_CONTENT_LENGTH'] = 5 * 1024 * 1024
|
||||
CONFIG_FILE = 'druckkalkulation_config.yaml'
|
||||
|
||||
|
||||
def image_dimensions(filepath):
|
||||
"""Liest Pixelbreite und -hoehe aus PNG/JPEG/WebP ohne externe Libs."""
|
||||
with open(filepath, 'rb') as f:
|
||||
head = f.read(64)
|
||||
if head[:8] == b'\x89PNG\r\n\x1a\n':
|
||||
w, h = struct.unpack('>II', head[16:24])
|
||||
return w, h
|
||||
if head[:2] == b'\xff\xd8':
|
||||
i = 2
|
||||
while i < len(head) - 1:
|
||||
if head[i] != 0xFF:
|
||||
break
|
||||
marker = head[i+1]
|
||||
if marker in (0xC0, 0xC1, 0xC2):
|
||||
h, w = struct.unpack('>HH', head[i+5:i+9])
|
||||
return w, h
|
||||
length = struct.unpack('>H', head[i+2:i+4])[0]
|
||||
i += 2 + length
|
||||
if head[:4] == b'RIFF' and head[8:12] == b'WEBP':
|
||||
if head[12:16] == b'VP8 ':
|
||||
w, h = struct.unpack('<HH', head[26:30])
|
||||
return (w & 0x3FFF) * 2, (h & 0x3FFF) * 2
|
||||
if head[12:16] == b'VP8L':
|
||||
bits = struct.unpack('<I', head[21:25])[0]
|
||||
return (bits & 0x3FFF) + 1, ((bits >> 14) & 0x3FFF) + 1
|
||||
return None, None
|
||||
LOGO_FILE = 'static/logo.png'
|
||||
|
||||
DEFAULT_VALUES = {
|
||||
@@ -285,11 +257,7 @@ def invoice_pdf():
|
||||
logo_path = os.path.join('static', logo_name) if logo_name else ''
|
||||
if logo_name and os.path.exists(logo_path):
|
||||
pdf.image(logo_path, x=155, y=8, w=40)
|
||||
img_w, img_h = image_dimensions(logo_path)
|
||||
if img_w and img_h:
|
||||
logo_bottom = 8 + 40 * (img_h / img_w)
|
||||
else:
|
||||
logo_bottom = 8 + 20
|
||||
logo_bottom = 50
|
||||
else:
|
||||
pdf.set_font("Arial", "B", 18)
|
||||
pdf.set_xy(150, 15)
|
||||
@@ -300,11 +268,10 @@ def invoice_pdf():
|
||||
pdf.set_text_color(0, 0, 0)
|
||||
logo_bottom = pdf.get_y()
|
||||
|
||||
# Firmendaten rechts unter Logo
|
||||
# Firmendaten rechts unter Logo (fester Abstand)
|
||||
right_x = 150
|
||||
info_y = logo_bottom + 3
|
||||
pdf.set_font("Arial", "B", 9)
|
||||
pdf.set_xy(right_x, info_y)
|
||||
pdf.set_xy(right_x, logo_bottom)
|
||||
pdf.cell(col_w, 4, firmen_name, ln=True, align='R')
|
||||
pdf.set_font("Arial", "", 8)
|
||||
if firmen_adresse:
|
||||
|
||||
Reference in New Issue
Block a user