Display PDFs in your Dash apps.
Made by Ploomber with ❤️
Deploy your Dash application on Ploomber.io for free.
dash-pdf.mp4
Live demo: dash-pdf.ploomberapp.io
pip install dash-pdf
from dash import Dash, html
import dash_pdf
import requests
from pathlib import Path
import dash
dash._dash_renderer._set_react_version("18.2.0")
app = Dash(__name__)
# Download the PDF and read it as bytes
url = 'https://css4.pub/2015/textbook/somatosensory.pdf'
response = requests.get(url)
pdf_bytes = response.content
# Alternatively, you can read a local PDF file
# pdf_bytes = Path('path/to/local/file.pdf').read_bytes()
app.layout = html.Div([
dash_pdf.PDF(
id='pdf-viewer',
# Pass the PDF content as bytes, you can also pass a URL
data=pdf_bytes,
# use these to customize the class names
buttonClassName="",
labelClassName="",
controlsClassName="",
)
])
if __name__ == '__main__':
app.run_server(debug=True)
cd demo
pip install -r requirements.txt
python app.py
Open: http://localhost:8050
# install js dependencies
npm install
# install python package in editable mode
pip install -e .
# install other python dependencies
pip install -r requirements.txt
pip install -r tests/requirements.txt
npm run build
python demo.py
# generate
npm run build
python setup.py sdist bdist_wheel
ls dist
# test artifact
pip install dash dist/dash_pdf-0.0.1.tar.gz
python demo/app.py
# upload
pip install twine
twine upload dist/*
# clean up
rm -rf dist