Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!