Flask/xhtml2pdf: CSS-Parsing Problem
Verfasst: Samstag 28. Juli 2018, 09:59
Folgendes Problem:
ich habe eine winzige Flask-App die via Web-Frontend über einige Forms Benutzereingaben entgegen nimmt und in einer Methode verarbeitet. Dabei werden die Werte in ein einem Jinja2-HTML-Template gerendert und der Rückgabewert davon (das gerenderte HTML) vom xhtml2pdf als PDF auf Platte gelegt. Das *tut* perse auch, nur hat xhtml2pdf Probleme das CSS zu parsen.
Konkret:
CSS:
Und der Hinweis:
Ich habe keinen blassen von CSS, es wird *so* allerdings korrekt von Flask als auch via direkten Browser-Aufruf gerendert, nur das PDF-Tool kommt damit nicht klar. Was mache ich falsch?
ich habe eine winzige Flask-App die via Web-Frontend über einige Forms Benutzereingaben entgegen nimmt und in einer Methode verarbeitet. Dabei werden die Werte in ein einem Jinja2-HTML-Template gerendert und der Rückgabewert davon (das gerenderte HTML) vom xhtml2pdf als PDF auf Platte gelegt. Das *tut* perse auch, nur hat xhtml2pdf Probleme das CSS zu parsen.
Konkret:
Code: Alles auswählen
@app.route('/test/', methods=('POST', 'GET'))
def test():
if request.method == 'POST':
html = render_template('output.html', foo=bar, fancy=value)
result_file = open('output.pdf', "w+b")
pisa.CreatePDF(html, dest=result_file)
result_file.close()
return render_template('output.html')
Code: Alles auswählen
#logo {
margin-top: 60px;
padding-left: 60px;
padding-right: 60px;
float: left;
}
#address {
margin-top: 60px;
padding-left: 5px;
padding-right: 90px;
padding-bottom: 20px;
padding-top: 20px;
float: right;
border-style: solid;
border-width: 0.5px;
font-family: 'Times';
font-size: 12pt;
}
#date {
margin-top: 270px;
padding-right: 130px;
text-align: right;
font-family: 'Helvetica';
font-size: 12pt;
}
#text {
margin-top: 150px;
padding-left: 60px;
padding-right: 60px;
font-family: 'Helvetica';
font-size: 12pt;
}
#greetings {
margin-top: 60px;
margin-left: 60px;
margin-right: 450px;
border-style: solid;
border-width: 0.5px;
padding: 3px;
font-family: 'Helvetica';
font-size: 12pt;
}
body {
height: 297mm;
width: 210mm;
margin-left: auto;
margin-right: auto;
border-style: solid;
border-width: 0.5px;
}
Code: Alles auswählen
127.0.0.1 - - [28/Jul/2018 10:50:28] "GET /static/style.css HTTP/1.1" 200 -
Selector name or qualifier expected:: ('', '"#logo {\\n margin-t')
127.0.0.1 - - [28/Jul/2018 10:50:28] "GET /static/logo.png HTTP/1.1" 200 -
127.0.0.1 - - [28/Jul/2018 10:50:28] "GET /static/logo.png HTTP/1.1" 200 -
127.0.0.1 - - [28/Jul/2018 10:50:28] "POST /test/ HTTP/1.1" 200 -