streamlit-pdf-viewer is an active Streamlit component designed for visualizing and manipulating PDF documents directly within Streamlit applications. It currently stands at version 0.0.28, with a consistent release cadence, frequently adding new features like scroll behavior, zoom controls, and annotation capabilities. The library leverages pdf.js for rendering and supports annotations, text rendering, and various display options.
pip install streamlit-pdf-viewerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to display a PDF from a URL and how to upload and display a PDF file using `st.file_uploader`, ensuring the uploaded file persists across Streamlit reruns with `st.session_state`.
Review the official documentation and adapt your code to use the current `pdf_viewer` function signature and parameters. The `legacy` parameter or explicit legacy calls are no longer supported.
Always provide an explicit `width` parameter (e.g., `width=700` or `width='100%'`) when using `pdf_viewer` inside `st.tabs` or `st.expander` components.
Store the `UploadedFile` (or its byte content) in `st.session_state` after it's uploaded. Always retrieve the PDF data from `st.session_state` for viewing to ensure persistence.
This issue is often PDF-specific. If encountered, try simplifying the PDF (e.g., re-saving it with a PDF editor) or investigate the specific content of the problematic PDF. Report the issue on the GitHub repository with the problematic PDF if it persists.
Ensure that the data passed to `pdf_viewer` is always valid PDF bytes or a URL. For `st.file_uploader`, store the uploaded file's `getvalue()` in `st.session_state` and retrieve it from there before passing to the viewer. Add checks to ensure the data is not `None`.
For local files, it's recommended to either use `st.file_uploader` (which handles reading the file into memory) or read the file into bytes explicitly (e.g., `with open('path/to/file.pdf', 'rb') as f: pdf_bytes = f.read()`) and pass the bytes to `pdf_viewer`. Ensure any local paths used are absolute and accessible by the Streamlit process.First, ensure all `warnings` related to width and session state are addressed. Check the browser's developer console for JavaScript errors. Try accessing the deployed app in different browsers (e.g., Firefox has shown better compatibility in some cases). Ensure the PDF source (URL or uploaded bytes) is valid and accessible from the deployment environment.