streamlit-pdf 1.0.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- streamlit_pdf/__init__.py +170 -0
- streamlit_pdf/frontend/build/.gitignore +5 -0
- streamlit_pdf/frontend/build/assets/index-C1nTKtnz.css +1 -0
- streamlit_pdf/frontend/build/assets/index-GqC0CMgD.js +88 -0
- streamlit_pdf/frontend/build/cmaps/78-EUC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/78-EUC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/78-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/78-RKSJ-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/78-RKSJ-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/78-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/78ms-RKSJ-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/78ms-RKSJ-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/83pv-RKSJ-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/90ms-RKSJ-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/90ms-RKSJ-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/90msp-RKSJ-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/90msp-RKSJ-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/90pv-RKSJ-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/90pv-RKSJ-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Add-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Add-RKSJ-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Add-RKSJ-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Add-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-0.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-1.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-2.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-3.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-4.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-5.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-6.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-GB1-0.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-GB1-1.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-GB1-2.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-GB1-3.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-GB1-4.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-GB1-5.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-0.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-1.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-2.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-3.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-4.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-5.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-6.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-Korea1-0.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-Korea1-1.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-Korea1-2.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/B5-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/B5-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/B5pc-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/B5pc-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/CNS-EUC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/CNS-EUC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/CNS1-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/CNS1-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/CNS2-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/CNS2-V.bcmap +3 -0
- streamlit_pdf/frontend/build/cmaps/ETHK-B5-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/ETHK-B5-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/ETen-B5-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/ETen-B5-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/ETenms-B5-H.bcmap +3 -0
- streamlit_pdf/frontend/build/cmaps/ETenms-B5-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/EUC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/EUC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Ext-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Ext-RKSJ-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Ext-RKSJ-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Ext-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GB-EUC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GB-EUC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GB-H.bcmap +4 -0
- streamlit_pdf/frontend/build/cmaps/GB-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBK-EUC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBK-EUC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBK2K-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBK2K-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBKp-EUC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBKp-EUC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBT-EUC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBT-EUC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBT-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBT-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBTpc-EUC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBTpc-EUC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBpc-EUC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/GBpc-EUC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/HKdla-B5-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/HKdla-B5-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/HKdlb-B5-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/HKdlb-B5-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/HKgccs-B5-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/HKgccs-B5-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/HKm314-B5-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/HKm314-B5-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/HKm471-B5-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/HKm471-B5-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/HKscs-B5-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/HKscs-B5-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Hankaku.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Hiragana.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/KSC-EUC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/KSC-EUC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/KSC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/KSC-Johab-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/KSC-Johab-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/KSC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/KSCms-UHC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/KSCms-UHC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/KSCpc-EUC-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/KSCpc-EUC-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Katakana.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/LICENSE +36 -0
- streamlit_pdf/frontend/build/cmaps/NWP-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/NWP-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/RKSJ-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/RKSJ-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/Roman.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniCNS-UCS2-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniCNS-UCS2-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniCNS-UTF16-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniCNS-UTF16-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniCNS-UTF32-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniCNS-UTF32-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniCNS-UTF8-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniCNS-UTF8-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniGB-UCS2-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniGB-UCS2-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniGB-UTF16-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniGB-UTF16-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniGB-UTF32-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniGB-UTF32-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniGB-UTF8-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniGB-UTF8-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS-UCS2-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS-UCS2-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS-UTF16-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS-UTF16-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS-UTF32-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS-UTF32-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS-UTF8-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS-UTF8-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniKS-UCS2-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniKS-UCS2-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniKS-UTF16-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniKS-UTF16-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniKS-UTF32-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniKS-UTF32-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniKS-UTF8-H.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/UniKS-UTF8-V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/V.bcmap +0 -0
- streamlit_pdf/frontend/build/cmaps/WP-Symbol.bcmap +0 -0
- streamlit_pdf/frontend/build/index.html +45 -0
- streamlit_pdf/frontend/build/standard_fonts/FoxitDingbats.pfb +0 -0
- streamlit_pdf/frontend/build/standard_fonts/FoxitFixed.pfb +0 -0
- streamlit_pdf/frontend/build/standard_fonts/FoxitFixedBold.pfb +0 -0
- streamlit_pdf/frontend/build/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
- streamlit_pdf/frontend/build/standard_fonts/FoxitFixedItalic.pfb +0 -0
- streamlit_pdf/frontend/build/standard_fonts/FoxitSerif.pfb +0 -0
- streamlit_pdf/frontend/build/standard_fonts/FoxitSerifBold.pfb +0 -0
- streamlit_pdf/frontend/build/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
- streamlit_pdf/frontend/build/standard_fonts/FoxitSerifItalic.pfb +0 -0
- streamlit_pdf/frontend/build/standard_fonts/FoxitSymbol.pfb +0 -0
- streamlit_pdf/frontend/build/standard_fonts/LICENSE_FOXIT +27 -0
- streamlit_pdf/frontend/build/standard_fonts/LICENSE_LIBERATION +102 -0
- streamlit_pdf/frontend/build/standard_fonts/LiberationSans-Bold.ttf +0 -0
- streamlit_pdf/frontend/build/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
- streamlit_pdf/frontend/build/standard_fonts/LiberationSans-Italic.ttf +0 -0
- streamlit_pdf/frontend/build/standard_fonts/LiberationSans-Regular.ttf +0 -0
- streamlit_pdf/frontend/build/workers/pdf.worker.min.mjs +29 -0
- streamlit_pdf/frontend/index.html +44 -0
- streamlit_pdf-1.0.5.dist-info/METADATA +147 -0
- streamlit_pdf-1.0.5.dist-info/RECORD +198 -0
- streamlit_pdf-1.0.5.dist-info/WHEEL +5 -0
- streamlit_pdf-1.0.5.dist-info/licenses/LICENSE +174 -0
- streamlit_pdf-1.0.5.dist-info/licenses/NOTICES +4180 -0
- streamlit_pdf-1.0.5.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Copyright 2025 Snowflake Inc.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
import os
|
|
17
|
+
import streamlit.components.v1 as components
|
|
18
|
+
import streamlit as st
|
|
19
|
+
import io
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import Union, Optional, Dict, Any
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Create a _RELEASE constant. We'll set this to False while we're developing
|
|
25
|
+
# the component, and True when we're ready to package and distribute it.
|
|
26
|
+
# (This is, of course, optional - there are innumerable ways to manage your
|
|
27
|
+
# release process.)
|
|
28
|
+
_DEV = os.environ.get("DEV", False)
|
|
29
|
+
_RELEASE = not _DEV
|
|
30
|
+
|
|
31
|
+
# Declare a Streamlit component for PDF viewing
|
|
32
|
+
if not _RELEASE:
|
|
33
|
+
_component_func = components.declare_component(
|
|
34
|
+
"pdf_viewer",
|
|
35
|
+
url="http://localhost:3001",
|
|
36
|
+
)
|
|
37
|
+
else:
|
|
38
|
+
# When we're distributing a production version of the component, we'll
|
|
39
|
+
# replace the `url` param with `path`, and point it to the component's
|
|
40
|
+
# build directory:
|
|
41
|
+
parent_dir = os.path.dirname(os.path.abspath(__file__))
|
|
42
|
+
build_dir = os.path.join(parent_dir, "frontend/build")
|
|
43
|
+
|
|
44
|
+
_component_func = components.declare_component("pdf_viewer", path=build_dir)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def pdf_viewer(
|
|
48
|
+
file: Union[str, bytes, Path, io.BytesIO, io.RawIOBase, io.BufferedReader],
|
|
49
|
+
height: int = 600,
|
|
50
|
+
key: Optional[str] = None,
|
|
51
|
+
) -> Optional[Dict[str, Any]]:
|
|
52
|
+
"""Create a new instance of the PDF viewer component.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
Parameters
|
|
56
|
+
----------
|
|
57
|
+
file : str, bytes, Path, io.BytesIO, io.RawIOBase, or io.BufferedReader
|
|
58
|
+
The PDF file to display. This can be:
|
|
59
|
+
- A URL to a PDF file (e.g., "https://example.com/document.pdf")
|
|
60
|
+
- A local file path (e.g., "./documents/sample.pdf")
|
|
61
|
+
- Raw bytes of a PDF file
|
|
62
|
+
- A pathlib.Path object pointing to a PDF file
|
|
63
|
+
- A BytesIO object containing PDF data
|
|
64
|
+
- A file-like object containing PDF data
|
|
65
|
+
- Base64 encoded PDF data URI
|
|
66
|
+
height : int, optional
|
|
67
|
+
The height of the PDF viewer in pixels. Default is 600.
|
|
68
|
+
key : str or None, optional
|
|
69
|
+
An optional key that uniquely identifies this component. If this is
|
|
70
|
+
None, and the component's arguments are changed, the component will
|
|
71
|
+
be re-mounted in the Streamlit frontend and lose its current state.
|
|
72
|
+
|
|
73
|
+
Returns
|
|
74
|
+
-------
|
|
75
|
+
None
|
|
76
|
+
|
|
77
|
+
Examples
|
|
78
|
+
--------
|
|
79
|
+
Basic usage with a URL:
|
|
80
|
+
>>> pdf_viewer("https://example.com/document.pdf")
|
|
81
|
+
|
|
82
|
+
With custom height:
|
|
83
|
+
>>> pdf_viewer(
|
|
84
|
+
... file="./documents/report.pdf",
|
|
85
|
+
... height=1000
|
|
86
|
+
... )
|
|
87
|
+
|
|
88
|
+
Loading from bytes:
|
|
89
|
+
>>> with open("document.pdf", "rb") as f:
|
|
90
|
+
... pdf_bytes = f.read()
|
|
91
|
+
>>> pdf_viewer(pdf_bytes)
|
|
92
|
+
|
|
93
|
+
Loading from a Path object:
|
|
94
|
+
>>> from pathlib import Path
|
|
95
|
+
>>> pdf_viewer(Path("./documents/report.pdf"))
|
|
96
|
+
|
|
97
|
+
Loading from a BytesIO object:
|
|
98
|
+
>>> import io
|
|
99
|
+
>>> with open("document.pdf", "rb") as f:
|
|
100
|
+
... pdf_buffer = io.BytesIO(f.read())
|
|
101
|
+
>>> pdf_viewer(pdf_buffer)
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
# Process the file parameter
|
|
105
|
+
processed_file = _process_file_input(file)
|
|
106
|
+
|
|
107
|
+
# Call the component function with processed arguments
|
|
108
|
+
component_value = _component_func(
|
|
109
|
+
file=processed_file, height=height, key=key, default=None
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
return component_value
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _process_file_input(
|
|
116
|
+
file: Union[str, bytes, Path, io.BytesIO, io.RawIOBase, io.BufferedReader],
|
|
117
|
+
) -> str:
|
|
118
|
+
"""Process different types of file inputs into a format the frontend can handle.
|
|
119
|
+
|
|
120
|
+
Parameters
|
|
121
|
+
----------
|
|
122
|
+
file : str, bytes, Path, io.BytesIO, io.RawIOBase, or io.BufferedReader
|
|
123
|
+
The input file in various formats
|
|
124
|
+
|
|
125
|
+
Returns
|
|
126
|
+
-------
|
|
127
|
+
str
|
|
128
|
+
A URL that the frontend can use to load the PDF
|
|
129
|
+
"""
|
|
130
|
+
# Handle empty string case - return empty string to let frontend handle it
|
|
131
|
+
if isinstance(file, str) and not file:
|
|
132
|
+
return ""
|
|
133
|
+
|
|
134
|
+
if isinstance(file, str) and (
|
|
135
|
+
file.startswith(("http://", "https://", "data:application/pdf"))
|
|
136
|
+
):
|
|
137
|
+
# For URLs and data URIs, use them directly
|
|
138
|
+
return file
|
|
139
|
+
else:
|
|
140
|
+
# For local files or raw data, process and store in media file manager
|
|
141
|
+
coordinates = st._main._get_delta_path_str()
|
|
142
|
+
|
|
143
|
+
# Convert data to appropriate format
|
|
144
|
+
data_or_filename: Union[bytes, str, None]
|
|
145
|
+
if isinstance(file, (str, bytes)):
|
|
146
|
+
# Pass strings and bytes through unchanged
|
|
147
|
+
data_or_filename = file
|
|
148
|
+
elif isinstance(file, Path):
|
|
149
|
+
data_or_filename = str(file)
|
|
150
|
+
elif isinstance(file, io.BytesIO):
|
|
151
|
+
file.seek(0)
|
|
152
|
+
data_or_filename = file.getvalue()
|
|
153
|
+
elif isinstance(file, (io.RawIOBase, io.BufferedReader)):
|
|
154
|
+
file.seek(0)
|
|
155
|
+
data_or_filename = file.read()
|
|
156
|
+
else:
|
|
157
|
+
data_or_filename = None
|
|
158
|
+
|
|
159
|
+
if data_or_filename is None:
|
|
160
|
+
raise RuntimeError(f"Cannot process provided data of type: {type(file)}")
|
|
161
|
+
|
|
162
|
+
# Add to media file manager
|
|
163
|
+
from streamlit.runtime import Runtime
|
|
164
|
+
|
|
165
|
+
runtime = Runtime.instance()
|
|
166
|
+
pdf_url = runtime.media_file_mgr.add(
|
|
167
|
+
data_or_filename, "application/pdf", coordinates
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
return pdf_url
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
._container_b38l5_18{width:100%;overflow:hidden;background-color:var(--background-color);position:relative}._content_b38l5_25{background-color:var(--secondary-background-color);overflow:auto;padding:0;position:relative;border-radius:8px}._noFileContainer_b38l5_33{display:flex;align-items:center;justify-content:center;padding:32px;background-color:var(--secondary-background-color);border:2px dashed rgba(0,0,0,.2);border-radius:8px;text-align:center}._noFileIcon_b38l5_44{font-size:48px;margin:0 auto 16px;display:block}._noFileTitle_b38l5_50{margin-top:8px;font-size:14px;font-weight:500;color:var(--text-color)}._noFileText_b38l5_57{margin-top:4px;font-size:14px;color:var(--text-color-secondary)}._loadingContainer_b38l5_63{display:flex;align-items:center;justify-content:center;padding:32px}._loadingContent_b38l5_70{text-align:center}._spinner_b38l5_74{border:2px solid var(--secondary-background-color);border-top:2px solid var(--primary-color);border-radius:50%;width:32px;height:32px;animation:_spin_b38l5_74 1s linear infinite;margin:0 auto}@keyframes _spin_b38l5_74{0%{transform:rotate(0)}to{transform:rotate(360deg)}}._loadingText_b38l5_89{margin-top:12px;font-size:14px;color:var(--text-color-secondary)}._errorContainer_b38l5_95{display:flex;align-items:center;justify-content:center;padding:32px;text-align:center}._errorIcon_b38l5_103{font-size:48px;margin:0 auto 16px;display:block}._errorTitle_b38l5_109{margin-top:8px;font-size:16px;font-weight:500;color:var(--text-color)}._errorText_b38l5_116{margin-top:4px;font-size:14px;color:var(--text-color-secondary)}._documentContainer_b38l5_122{width:100%;box-sizing:border-box;position:relative;padding-top:12px}._virtualContainer_b38l5_129{width:100%;position:relative}._virtualItem_b38l5_134{position:absolute;top:0;height:auto;padding-bottom:12px}._pageContainer_b38l5_141{display:block;background-color:var(--background-color);box-shadow:0 1px 3px #0000001a;border-radius:4px;overflow:visible;margin:0}._pdfPage_b38l5_150{display:block}._pdfPage_b38l5_150 canvas{display:block}._pagePlaceholder_b38l5_158{display:flex;align-items:center;justify-content:center;height:var(--default-page-height, 800px);background-color:var(--secondary-background-color);border:1px solid rgba(0,0,0,.1);color:var(--text-color-secondary);font-size:14px}._zoomControls_b38l5_170{display:flex;flex-direction:column;align-items:center;gap:0px;position:absolute;top:0;right:0;margin:.625rem .625rem 0 0;z-index:10;background-color:var(--background-color);border:none;border-radius:4px;box-shadow:0 0 0 2px #0000001a;transition:opacity .2s ease;opacity:0;padding:0;overflow:hidden}._zoomControls_b38l5_170._visible_b38l5_190{opacity:1;visibility:visible}._zoomButton_b38l5_195{background-color:transparent;color:var(--text-color);border:none;border-radius:0;width:29px;height:29px;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:16px;font-family:Source Sans,sans-serif;-webkit-user-select:none;user-select:none;padding:0;outline:none;box-sizing:border-box;position:relative}._zoomButton_b38l5_195 svg{display:block;width:100%;height:100%}._zoomButton_b38l5_195+._zoomButton_b38l5_195{border-top:1px solid rgba(128,128,128,.2)}._zoomButton_b38l5_195:first-child{border-top-left-radius:4px;border-top-right-radius:4px}._zoomButton_b38l5_195:last-child{border-bottom-left-radius:4px;border-bottom-right-radius:4px}._zoomButton_b38l5_195:hover:not(._disabled_b38l5_237){background-color:#0000000d}._zoomButton_b38l5_195:focus{box-shadow:0 0 2px 2px #0096ff}._zoomButton_b38l5_195:focus:not(:focus-visible){box-shadow:none}._zoomButton_b38l5_195._disabled_b38l5_237{cursor:not-allowed}._zoomButton_b38l5_195._disabled_b38l5_237 svg{opacity:.25}body{margin:0;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}
|