The Pdf class allows you to display a PDF hosted remotely or locally in the chatbot UI. This class either takes a URL of a PDF hosted online, or the path of a local PDF.

Attributes

name
str

The name of the PDF to be displayed in the UI.

display
ElementDisplay

Determines how the PDF element should be displayed in the UI. Choices are “side” (default), “inline”, or “page”.

url
str

The remote URL of the PDF file. Must provide url for a remote PDF (or either path or content for a local PDF).

path
str

The local file path of the PDF. Must provide either path or content for a local PDF (or url for a remote PDF).

content
bytes

The file content of the PDF in bytes format. Must provide either path or content for a local PDF (or url for a remote PDF).

Usage with message scope

Code Example
import chainlit as cl

# Sending a pdf with the local file path
elements = [
  cl.Pdf(name="pdf1", display="inline", path="./pdf1.pdf")
]

cl.Message(content="Look at this local pdf!", elements=elements).send()

Usage without scope

Code Example
import chainlit as cl

# Sending a pdf with the remote url
pdf1 = cl.Pdf(name="pdf1", display="inline", url="https://example.com/example.pdf")
pdf1.send()

# Sending a pdf with file content as bytes
with open("./pdf2.pdf", "rb") as f:
    pdf_content = f.read()
    pdf2 = cl.Pdf(name="pdf2", display="inline", content=pdf_content)
    pdf2.send()