PDF#
Open this notebook in Jupyterlite | Download this notebook from GitHub (right-click to download).
import panel as pn
pn.extension()
The PDF pane embeds a .pdf document in a panel if provided a local path, raw bytes or a file-like object, or will link to a remote file if provided a URL.
Parameters:#
For details on other options for customizing the component see the layout and styling how-to guides.
embed(boolean, default=False): If given a URL to a file this determines whether the PDF will be embedded as base64 or merely linked to.object(str, bytes or object): The PDF file to display. Can be a string orpathlib.Pathpointing to a local or remote file, rawbytes, a file-like object, or an object with a_repr_pdf_method.start_page(int, default=1): The page of the PDF to show when it is first loaded.
The PDF pane can be pointed at any local or remote .pdf file. If given a URL starting with http or https, the embed parameter determines whether the PDF will be embedded or linked to:
pdf_pane = pn.pane.PDF('https://assets.holoviz.org/panel/samples/pdf_sample.pdf', width=700, height=1000)
pdf_pane
Like any other pane, the PDF pane can be updated by setting the object parameter:
pdf_pane.object = 'https://assets.holoviz.org/panel/samples/pdf_sample2.pdf'
The start_page parameter controls which page is shown when the document is first loaded:
pn.pane.PDF(
'https://assets.holoviz.org/panel/samples/pdf_sample2.pdf', start_page=2, width=700, height=1000
)
In addition to file paths and URLs, the PDF pane also accepts raw bytes or a file-like object such as an io.BytesIO, which is useful when a PDF is generated in memory or uploaded by a user:
from io import BytesIO
from urllib.request import urlopen
pdf_bytes = urlopen('https://assets.holoviz.org/panel/samples/pdf_sample.pdf').read()
pn.pane.PDF(BytesIO(pdf_bytes), width=700, height=1000)
Open this notebook in Jupyterlite | Download this notebook from GitHub (right-click to download).