Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

322
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda