I am making a dashboard app and I want to add the Print PDF button just like https://vanguard-report.herokuapp.com/ report, can anyone please explain its working ?
If you look at the source code at
https://github.com/plotly/dash-vanguard-report/blob/master/app.py
you will find links to various external resources including
https://codepen.io/bcd/pen/YaXojL.js
https://codepen.io/bcd/pen/KQrXdb.css
The JavaScript file calls window.print()
when the button is clicked, and the css file sets up the print layout in @media print
.
2 Likes
This example code is not available anymore
1 Like
You can print pdf like this:
- install this package python -m pip install visdcc
- import visdcc
- Add these lines in the layout
html.Div([
html.Button(âDownloadâ, id=âclick1â),
visdcc.Run_js(id = âjavascriptâ)
])
- add callback
@app.callback(
Output(âjavascriptâ, ârunâ),
[Input(âclick1â, ân_clicksâ)])
def myfun(x):
if x:
return âwindow.print()â
return ââ
- save it, run the code and click download button. It will work 100%
6.Thanks