|
@@ -1,13 +1,10 @@
|
|
#!/usr/bin/env python3
|
|
#!/usr/bin/env python3
|
|
from io import BytesIO
|
|
from io import BytesIO
|
|
-from pathlib import Path
|
|
|
|
|
|
|
|
import cairo
|
|
import cairo
|
|
|
|
|
|
from nicegui import ui
|
|
from nicegui import ui
|
|
|
|
|
|
-PDF_PATH = Path('output.pdf')
|
|
|
|
-
|
|
|
|
|
|
|
|
def generate_svg() -> str:
|
|
def generate_svg() -> str:
|
|
output = BytesIO()
|
|
output = BytesIO()
|
|
@@ -25,7 +22,7 @@ def generate_pdf() -> bytes:
|
|
return output.getvalue()
|
|
return output.getvalue()
|
|
|
|
|
|
|
|
|
|
-def draw(surface: cairo.SVGSurface) -> None:
|
|
|
|
|
|
+def draw(surface: cairo.Surface) -> None:
|
|
context = cairo.Context(surface)
|
|
context = cairo.Context(surface)
|
|
context.select_font_face('Arial', cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
|
|
context.select_font_face('Arial', cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
|
|
context.set_font_size(20)
|
|
context.set_font_size(20)
|
|
@@ -37,7 +34,6 @@ def draw(surface: cairo.SVGSurface) -> None:
|
|
|
|
|
|
def update() -> None:
|
|
def update() -> None:
|
|
preview.content = generate_svg()
|
|
preview.content = generate_svg()
|
|
- PDF_PATH.write_bytes(generate_pdf())
|
|
|
|
|
|
|
|
|
|
|
|
with ui.row():
|
|
with ui.row():
|
|
@@ -46,6 +42,6 @@ with ui.row():
|
|
email = ui.input('E-Mail', placeholder='Enter your E-Mail address', on_change=update)
|
|
email = ui.input('E-Mail', placeholder='Enter your E-Mail address', on_change=update)
|
|
preview = ui.html().classes('border-2 border-gray-500')
|
|
preview = ui.html().classes('border-2 border-gray-500')
|
|
update()
|
|
update()
|
|
- ui.button('Download PDF', on_click=lambda: ui.download(PDF_PATH)).bind_visibility_from(name, 'value')
|
|
|
|
|
|
+ ui.button('PDF', on_click=lambda: ui.download(generate_pdf(), 'output.pdf')).bind_visibility_from(name, 'value')
|
|
|
|
|
|
ui.run()
|
|
ui.run()
|