How do I display a website written in Dash as a static PDF (Python)? How do I display a website written in Dash as a static PDF (Python)? flask flask

How do I display a website written in Dash as a static PDF (Python)?


You can use the print function of whatever browser you are using (usually control + p) and save it as PDF if all you are looking for is the static PDF file.

If you want more enhanced functionality you can add a print to PDF button like the one in one of the dash examples. It uses a js file to invoke the browser print functionality, see more detail. This way you can also use CSS to define the way the PDF output looks

The problem with using the python file to generate pdf directly is that dash only creates a JSON representation of the layout tree which is then assembled in the browser itself, see more.


You can use pdfkit in the following way:

import pdfkitpdfkit.from_url('http://local.dash.site', 'out.pdf')

The big difference from what you posted is that you could use the local web server to render the page.

As an alternative, you could also use https://wkhtmltopdf.org/This is the lib underneath pdfkit.


You can use the directions from the following link to create pdf:http://flask.pocoo.org/snippets/68/

render_template accepts only one positional arguments, the rest must be keyword arguments.