Skip to main content

A Streamlit component for viewing PDF files

Project description

streamlit-pdf

A lightweight Streamlit feature that seamlessly displays PDF files in your apps, allowing for simple, responsive, and clean document viewing with minimal effort.


📦 Installation

pip install streamlit[pdf]

Ensure you have Streamlit installed:


💡 Usage

Here's how to display a PDF file in your Streamlit app:

import streamlit as st

# Display PDF from URL
st.pdf("https://example.com/document.pdf")

# Display with custom height
st.pdf("path/to/document.pdf", height=600)

# Display uploaded file
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
if uploaded_file is not None:
    st.pdf(uploaded_file)

⚙️ API Reference

st.pdf(data, height=600)

Parameters:

  • data (str | Path | bytes | BytesIO): The PDF file to show. This can be one of the following:

    • A URL (string) for a hosted PDF file ("https://example.com/doc.pdf")
    • A path to a local PDF file ("./documents/sample.pdf")
    • A file-like object, e.g. a file opened with open or an UploadedFile returned by st.file_uploader
    • Raw bytes data
  • height (int, optional): Height of the PDF viewer in pixels. Default: 600


🖼️ Examples

Basic PDF Display

import streamlit as st

st.title("PDF Viewer Example")

# Display a PDF from URL
st.pdf("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf")

File Upload with PDF Display

import streamlit as st

st.title("Upload and View PDF")

uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
if uploaded_file is not None:
    st.pdf(uploaded_file)

Custom Height

import streamlit as st

# Display PDF with specific height
st.pdf("document.pdf", height=800)

# Display PDF with default height
st.pdf("document.pdf")

Reading from Local File

import streamlit as st

with open("document.pdf", "rb") as file:
    st.pdf(file.read(), height=700)

📝 Contributing

Feel free to file issues in our Streamlit Repository.

Contributions are welcome 🚀, however, please inform us before building a feature.

Development flow

Prerequisites:

uv venv .venv
source .venv/bin/activate
uv pip install -e '.[with-streamlit]' .
cd streamlit_pdf/frontend && npm install
  • Build the frontend once:
    npm run build
    
  • Or run the frontend in watch/development mode:
    npm run dev
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_pdf-2.0.1.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_pdf-2.0.1-py3-none-any.whl (2.1 MB view details)

Uploaded Python 3

File details

Details for the file streamlit_pdf-2.0.1.tar.gz.

File metadata

  • Download URL: streamlit_pdf-2.0.1.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for streamlit_pdf-2.0.1.tar.gz
Algorithm Hash digest
SHA256 c6306381d0eeb291d7a4f6eb16cfbf937560a29be78049c64251fa2c3276e1a2
MD5 1355ca0d38f3aeb5f0337b11b02d1ad2
BLAKE2b-256 e35d04487c85e3b5071b417451f1a910302d063ccd9f392457846bea271b340d

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_pdf-2.0.1.tar.gz:

Publisher: release.yml on streamlit/streamlit-pdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file streamlit_pdf-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: streamlit_pdf-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for streamlit_pdf-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8330d7f954e46edc7574b7e498378462555a8e25e829946abb78dbf5684b0a1e
MD5 89aa4202e1d07dc67ba9a6ee6c7d153b
BLAKE2b-256 6557ba77126eed2cb516feaf19b9f9d39af5be110b0a692415e772c7bbab7ed3

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_pdf-2.0.1-py3-none-any.whl:

Publisher: release.yml on streamlit/streamlit-pdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page