Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

324
Vistas
python or js code / library to export html elements of a Flask/Dash App

I have running a Flask Application with embedded Dash App. The application code is entirely written in python that renders html code. Now, I'd like to be able to export certain <html> elements to pdf.

python code for generating html:

import dash
from dash.dependencies import Input, Output, State
from dash import dcc
from dash import html, dash_table
import dash_bootstrap_components as dbc

html.Div(
    [
        dbc.Row(
            [
                dbc.Card(
                    [
                        dbc.CardHeader("Median"),
                        dbc.CardBody(
                            [
                                html.P(id="card"),
                            ]
                        ),
                    ],
                    id="stat",
                    color="light",
                ),
            ]
        )
    ]
)    

Here's the html generated by python code:

<div class="row">
    
  <div id="stat" class="card bg-light">
    <div class="card-header">Median</div>
  </div>
    
  <div class="card-body">
    <p id="card"></p>
  </div>
    
</div>

Is there a pythonic way of exporting html to pdf? I can also write Javascript if there is a way.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

1. Info on Dash => Html:

How to export a plotly dashboard app into a html standalone file to share with the others?

2. Html => Pdf:

2.1 pdfkit

import pdfkit
pdfkit.from_string('Shaurya GFG','GfG.pdf')

https://www.geeksforgeeks.org/python-convert-html-pdf/

https://github.com/JazzCore/python-pdfkit

2.2 xhtml2pdf

from xhtml2pdf import pisa            

result_file = open("test.pdf", "w+b")
pisa.CreatePDF(
  "<html><body><p>To PDF or not to PDF</p></body></html>",
  dest=result_file
)

https://pypi.org/project/xhtml2pdf/

3.3 selenium

Using the print feature of a browser and a pdf printer driver might also be an option:

how to save opened page as pdf in Selenium (Python)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda