有没有人知道一个HTML到PDF的转换器,无论是Flask或JavaScript/Jquery,与Bootstrap CSS工作?
我试过PDFkit,但我还没有得到它与Bootstrap的工作。而不是显示多列在Bootstrap网格,它把一切都放在左边,好像它是忽略了Bootstrap样式。
以下是我尝试过的:
@app.route('/test')
def test():
config = pdfkit.configuration(wkhtmltopdf="C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe")
report = render_template('test.html')
pdf = pdfkit.from_string(report, False, configuration=config)
response = make_response(pdf)
response.headers['Content-Type'] = 'application/pdf'
response.headers['Content-Disposition'] = 'inline; filename = report.pdf'
return response
字符串
还有HTML。我从Bootstrap网站借用了这个作为一个最小的例子:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--<link rel="stylesheet" href="static/css/bootstrap.min.css"> -->
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="jumbotron text-center">
<h1>My First Bootstrap Page</h1>
<p>Resize this responsive page to see the effect!</p>
</div>
<div class="container">
<div class="row">
<div class="col-sm-4">
<h3>Column 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
</div>
<div class="col-sm-4">
<h3>Column 2</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
</div>
<div class="col-sm-4">
<h3>Column 3</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
</div>
</div>
</div>
</body>
</html>
型
2条答案
按热度按时间eblbsuwk1#
我也遇到了同样的问题,但下面的方法帮助了我。一个单独的打印预览样式表将被应用。如果你想让样式表同时用于屏幕和打印,请用
all
替换print
。字符串
参考答案:https://www.w3schools.com/css/css3_mediaqueries.asp
ax6ht2ek2#
页面需要渲染。 您可以使用PDFKit!
https://pypi.python.org/pypi/pdfkit
https://github.com/JazzCore/python-pdfkit的
字符串