feat: tilføj rigtig PDF download via WeasyPrint
All checks were successful
Build and Deploy Erika CV / build-and-deploy (push) Successful in 58s
All checks were successful
Build and Deploy Erika CV / build-and-deploy (push) Successful in 58s
- /download route genererer PDF server-side - PDF ser ud som hjemmesiden (ikke browser-print) - Kompakt print-CSS til 1 A4-side - Knap downloader direkte i stedet for at åbne print-dialog
This commit is contained in:
15
app.py
15
app.py
@@ -1,6 +1,8 @@
|
||||
from flask import Flask, render_template, jsonify
|
||||
from flask import Flask, render_template, jsonify, send_file, request
|
||||
from weasyprint import HTML
|
||||
from datetime import datetime, timezone
|
||||
import os
|
||||
import io
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -11,6 +13,17 @@ GIT_COMMIT = os.getenv('GIT_COMMIT', 'unknown')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/download')
|
||||
def download_pdf():
|
||||
html = render_template('index.html', pdf_mode=True)
|
||||
pdf = HTML(string=html, base_url=request.host_url).write_pdf()
|
||||
return send_file(
|
||||
io.BytesIO(pdf),
|
||||
mimetype='application/pdf',
|
||||
as_attachment=True,
|
||||
download_name='Erika_Nielsen_CV.pdf'
|
||||
)
|
||||
|
||||
@app.route('/health')
|
||||
def health():
|
||||
return jsonify({
|
||||
|
||||
Reference in New Issue
Block a user