Socket
Socket
Sign inDemoInstall

streamlit-pdf-viewer

Package Overview
Dependencies
0
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    streamlit-pdf-viewer

Streamlit component for PDF visualisation and manipulation


Maintainers
1

Readme

License PyPI version Build Coverage Status

streamlit-pdf-viewer

Streamlit component that allows the visualisation and enrichment of PDF documents Tested on Chrome and Firefox. You can see an application in action here.

Work in progress

We are early in the development, and we appreciate new contributors.

If with version 0.0.8 the PDF is not shown, please upgrade.

Getting started

pip install streamlit-pdf-viewer

In your streamlit application, you can use it as:

import streamlit as st
from streamlit_pdf_viewer import pdf_viewer

pdf_viewer("str, path or bytes")

Options

Params

In the following table the list of parameters that can be provided to the pdf_viewer function:

namedescription
inputThe source of the PDF file. Accepts a file path, URL, or binary data.
widthWidth of the PDF viewer in pixels. It defaults to 700 pixels.
heightHeight of the PDF viewer in pixels. If not provided, the viewer shows the whole content.
annotationsA list of annotations to be overlaid on the PDF. Format is described here.
pages_vertical_spacingThe vertical space (in pixels) between each page of the PDF. Defaults to 2 pixels.
annotation_outline_sizeSize of the outline around each annotation in pixels. Defaults to 1 pixel.
renderingType of rendering: unwrap (default), legacy_iframe, or legacy_embed. The default value, unwrap shows the PDF document using pdf.js, and supports the visualisation of annotations. Other values are legacy_iframe and legacy_embed which use the legacy approach of injecting the document into an <embed> or <iframe>. They allow viewing the PDF using the viewer of the browser that contains additional features we are still working to implement in this component. IMPORTANT: :warning: The "legacy" methods work only with Firefox, and do not support annotations. :warning:
pages_to_renderFilter the rendering to a specific set of pages. By default, all pages are rendered.

Annotation format

The annotations format has been derived from the Grobid's coordinate formats, which are described as a list of "bounding boxes". The annotations are expressed as a dictionary of six elements, the page, x and y indicate the top left point. The color can be expressed following the html CSS convention.

Here an example:

[
   {
      "page": 1,
      "x": 220,
      "y": 155,
      "height": 22,
      "width": 65,
      "color": "red"
   },
[...]

The example shown in our screenshot can be found here.

Developers notes

Environment

  • Python >= 3.8
  • Node.js >= 16
  • Streamlit >= 1.28.2

Configure environment for development

First, make sure that _RELEASE = False in streamlit_pdf_viewer/__init__.py. To run the component in development mode, use the following commands:

streamlit run streamlit_pdf_viewer/__init__.py

cd frontend
npm run serve

These commands will start the Streamlit application and serve the Node.js component. Please make sure you're in the correct directory before running these commands.

Integrate into a streamlit application

  1. Build the frontend part:

    cd frontend
    export NODE_OPTIONS=--openssl-legacy-provider
    npm run build 
    
  2. Make sure that _RELEASE = True in streamlit_pdf_viewer/__init__.py.

  3. move to the streamlit_application and run

    pip install -e {path of component}
    

Release

bump-my-version bump patch | minor | major
git push
git push --tags 

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc