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.
Files changed (198) hide show
  1. streamlit_pdf/__init__.py +170 -0
  2. streamlit_pdf/frontend/build/.gitignore +5 -0
  3. streamlit_pdf/frontend/build/assets/index-C1nTKtnz.css +1 -0
  4. streamlit_pdf/frontend/build/assets/index-GqC0CMgD.js +88 -0
  5. streamlit_pdf/frontend/build/cmaps/78-EUC-H.bcmap +0 -0
  6. streamlit_pdf/frontend/build/cmaps/78-EUC-V.bcmap +0 -0
  7. streamlit_pdf/frontend/build/cmaps/78-H.bcmap +0 -0
  8. streamlit_pdf/frontend/build/cmaps/78-RKSJ-H.bcmap +0 -0
  9. streamlit_pdf/frontend/build/cmaps/78-RKSJ-V.bcmap +0 -0
  10. streamlit_pdf/frontend/build/cmaps/78-V.bcmap +0 -0
  11. streamlit_pdf/frontend/build/cmaps/78ms-RKSJ-H.bcmap +0 -0
  12. streamlit_pdf/frontend/build/cmaps/78ms-RKSJ-V.bcmap +0 -0
  13. streamlit_pdf/frontend/build/cmaps/83pv-RKSJ-H.bcmap +0 -0
  14. streamlit_pdf/frontend/build/cmaps/90ms-RKSJ-H.bcmap +0 -0
  15. streamlit_pdf/frontend/build/cmaps/90ms-RKSJ-V.bcmap +0 -0
  16. streamlit_pdf/frontend/build/cmaps/90msp-RKSJ-H.bcmap +0 -0
  17. streamlit_pdf/frontend/build/cmaps/90msp-RKSJ-V.bcmap +0 -0
  18. streamlit_pdf/frontend/build/cmaps/90pv-RKSJ-H.bcmap +0 -0
  19. streamlit_pdf/frontend/build/cmaps/90pv-RKSJ-V.bcmap +0 -0
  20. streamlit_pdf/frontend/build/cmaps/Add-H.bcmap +0 -0
  21. streamlit_pdf/frontend/build/cmaps/Add-RKSJ-H.bcmap +0 -0
  22. streamlit_pdf/frontend/build/cmaps/Add-RKSJ-V.bcmap +0 -0
  23. streamlit_pdf/frontend/build/cmaps/Add-V.bcmap +0 -0
  24. streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-0.bcmap +0 -0
  25. streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-1.bcmap +0 -0
  26. streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-2.bcmap +0 -0
  27. streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-3.bcmap +0 -0
  28. streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-4.bcmap +0 -0
  29. streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-5.bcmap +0 -0
  30. streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-6.bcmap +0 -0
  31. streamlit_pdf/frontend/build/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
  32. streamlit_pdf/frontend/build/cmaps/Adobe-GB1-0.bcmap +0 -0
  33. streamlit_pdf/frontend/build/cmaps/Adobe-GB1-1.bcmap +0 -0
  34. streamlit_pdf/frontend/build/cmaps/Adobe-GB1-2.bcmap +0 -0
  35. streamlit_pdf/frontend/build/cmaps/Adobe-GB1-3.bcmap +0 -0
  36. streamlit_pdf/frontend/build/cmaps/Adobe-GB1-4.bcmap +0 -0
  37. streamlit_pdf/frontend/build/cmaps/Adobe-GB1-5.bcmap +0 -0
  38. streamlit_pdf/frontend/build/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
  39. streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-0.bcmap +0 -0
  40. streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-1.bcmap +0 -0
  41. streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-2.bcmap +0 -0
  42. streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-3.bcmap +0 -0
  43. streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-4.bcmap +0 -0
  44. streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-5.bcmap +0 -0
  45. streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-6.bcmap +0 -0
  46. streamlit_pdf/frontend/build/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
  47. streamlit_pdf/frontend/build/cmaps/Adobe-Korea1-0.bcmap +0 -0
  48. streamlit_pdf/frontend/build/cmaps/Adobe-Korea1-1.bcmap +0 -0
  49. streamlit_pdf/frontend/build/cmaps/Adobe-Korea1-2.bcmap +0 -0
  50. streamlit_pdf/frontend/build/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
  51. streamlit_pdf/frontend/build/cmaps/B5-H.bcmap +0 -0
  52. streamlit_pdf/frontend/build/cmaps/B5-V.bcmap +0 -0
  53. streamlit_pdf/frontend/build/cmaps/B5pc-H.bcmap +0 -0
  54. streamlit_pdf/frontend/build/cmaps/B5pc-V.bcmap +0 -0
  55. streamlit_pdf/frontend/build/cmaps/CNS-EUC-H.bcmap +0 -0
  56. streamlit_pdf/frontend/build/cmaps/CNS-EUC-V.bcmap +0 -0
  57. streamlit_pdf/frontend/build/cmaps/CNS1-H.bcmap +0 -0
  58. streamlit_pdf/frontend/build/cmaps/CNS1-V.bcmap +0 -0
  59. streamlit_pdf/frontend/build/cmaps/CNS2-H.bcmap +0 -0
  60. streamlit_pdf/frontend/build/cmaps/CNS2-V.bcmap +3 -0
  61. streamlit_pdf/frontend/build/cmaps/ETHK-B5-H.bcmap +0 -0
  62. streamlit_pdf/frontend/build/cmaps/ETHK-B5-V.bcmap +0 -0
  63. streamlit_pdf/frontend/build/cmaps/ETen-B5-H.bcmap +0 -0
  64. streamlit_pdf/frontend/build/cmaps/ETen-B5-V.bcmap +0 -0
  65. streamlit_pdf/frontend/build/cmaps/ETenms-B5-H.bcmap +3 -0
  66. streamlit_pdf/frontend/build/cmaps/ETenms-B5-V.bcmap +0 -0
  67. streamlit_pdf/frontend/build/cmaps/EUC-H.bcmap +0 -0
  68. streamlit_pdf/frontend/build/cmaps/EUC-V.bcmap +0 -0
  69. streamlit_pdf/frontend/build/cmaps/Ext-H.bcmap +0 -0
  70. streamlit_pdf/frontend/build/cmaps/Ext-RKSJ-H.bcmap +0 -0
  71. streamlit_pdf/frontend/build/cmaps/Ext-RKSJ-V.bcmap +0 -0
  72. streamlit_pdf/frontend/build/cmaps/Ext-V.bcmap +0 -0
  73. streamlit_pdf/frontend/build/cmaps/GB-EUC-H.bcmap +0 -0
  74. streamlit_pdf/frontend/build/cmaps/GB-EUC-V.bcmap +0 -0
  75. streamlit_pdf/frontend/build/cmaps/GB-H.bcmap +4 -0
  76. streamlit_pdf/frontend/build/cmaps/GB-V.bcmap +0 -0
  77. streamlit_pdf/frontend/build/cmaps/GBK-EUC-H.bcmap +0 -0
  78. streamlit_pdf/frontend/build/cmaps/GBK-EUC-V.bcmap +0 -0
  79. streamlit_pdf/frontend/build/cmaps/GBK2K-H.bcmap +0 -0
  80. streamlit_pdf/frontend/build/cmaps/GBK2K-V.bcmap +0 -0
  81. streamlit_pdf/frontend/build/cmaps/GBKp-EUC-H.bcmap +0 -0
  82. streamlit_pdf/frontend/build/cmaps/GBKp-EUC-V.bcmap +0 -0
  83. streamlit_pdf/frontend/build/cmaps/GBT-EUC-H.bcmap +0 -0
  84. streamlit_pdf/frontend/build/cmaps/GBT-EUC-V.bcmap +0 -0
  85. streamlit_pdf/frontend/build/cmaps/GBT-H.bcmap +0 -0
  86. streamlit_pdf/frontend/build/cmaps/GBT-V.bcmap +0 -0
  87. streamlit_pdf/frontend/build/cmaps/GBTpc-EUC-H.bcmap +0 -0
  88. streamlit_pdf/frontend/build/cmaps/GBTpc-EUC-V.bcmap +0 -0
  89. streamlit_pdf/frontend/build/cmaps/GBpc-EUC-H.bcmap +0 -0
  90. streamlit_pdf/frontend/build/cmaps/GBpc-EUC-V.bcmap +0 -0
  91. streamlit_pdf/frontend/build/cmaps/H.bcmap +0 -0
  92. streamlit_pdf/frontend/build/cmaps/HKdla-B5-H.bcmap +0 -0
  93. streamlit_pdf/frontend/build/cmaps/HKdla-B5-V.bcmap +0 -0
  94. streamlit_pdf/frontend/build/cmaps/HKdlb-B5-H.bcmap +0 -0
  95. streamlit_pdf/frontend/build/cmaps/HKdlb-B5-V.bcmap +0 -0
  96. streamlit_pdf/frontend/build/cmaps/HKgccs-B5-H.bcmap +0 -0
  97. streamlit_pdf/frontend/build/cmaps/HKgccs-B5-V.bcmap +0 -0
  98. streamlit_pdf/frontend/build/cmaps/HKm314-B5-H.bcmap +0 -0
  99. streamlit_pdf/frontend/build/cmaps/HKm314-B5-V.bcmap +0 -0
  100. streamlit_pdf/frontend/build/cmaps/HKm471-B5-H.bcmap +0 -0
  101. streamlit_pdf/frontend/build/cmaps/HKm471-B5-V.bcmap +0 -0
  102. streamlit_pdf/frontend/build/cmaps/HKscs-B5-H.bcmap +0 -0
  103. streamlit_pdf/frontend/build/cmaps/HKscs-B5-V.bcmap +0 -0
  104. streamlit_pdf/frontend/build/cmaps/Hankaku.bcmap +0 -0
  105. streamlit_pdf/frontend/build/cmaps/Hiragana.bcmap +0 -0
  106. streamlit_pdf/frontend/build/cmaps/KSC-EUC-H.bcmap +0 -0
  107. streamlit_pdf/frontend/build/cmaps/KSC-EUC-V.bcmap +0 -0
  108. streamlit_pdf/frontend/build/cmaps/KSC-H.bcmap +0 -0
  109. streamlit_pdf/frontend/build/cmaps/KSC-Johab-H.bcmap +0 -0
  110. streamlit_pdf/frontend/build/cmaps/KSC-Johab-V.bcmap +0 -0
  111. streamlit_pdf/frontend/build/cmaps/KSC-V.bcmap +0 -0
  112. streamlit_pdf/frontend/build/cmaps/KSCms-UHC-H.bcmap +0 -0
  113. streamlit_pdf/frontend/build/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
  114. streamlit_pdf/frontend/build/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
  115. streamlit_pdf/frontend/build/cmaps/KSCms-UHC-V.bcmap +0 -0
  116. streamlit_pdf/frontend/build/cmaps/KSCpc-EUC-H.bcmap +0 -0
  117. streamlit_pdf/frontend/build/cmaps/KSCpc-EUC-V.bcmap +0 -0
  118. streamlit_pdf/frontend/build/cmaps/Katakana.bcmap +0 -0
  119. streamlit_pdf/frontend/build/cmaps/LICENSE +36 -0
  120. streamlit_pdf/frontend/build/cmaps/NWP-H.bcmap +0 -0
  121. streamlit_pdf/frontend/build/cmaps/NWP-V.bcmap +0 -0
  122. streamlit_pdf/frontend/build/cmaps/RKSJ-H.bcmap +0 -0
  123. streamlit_pdf/frontend/build/cmaps/RKSJ-V.bcmap +0 -0
  124. streamlit_pdf/frontend/build/cmaps/Roman.bcmap +0 -0
  125. streamlit_pdf/frontend/build/cmaps/UniCNS-UCS2-H.bcmap +0 -0
  126. streamlit_pdf/frontend/build/cmaps/UniCNS-UCS2-V.bcmap +0 -0
  127. streamlit_pdf/frontend/build/cmaps/UniCNS-UTF16-H.bcmap +0 -0
  128. streamlit_pdf/frontend/build/cmaps/UniCNS-UTF16-V.bcmap +0 -0
  129. streamlit_pdf/frontend/build/cmaps/UniCNS-UTF32-H.bcmap +0 -0
  130. streamlit_pdf/frontend/build/cmaps/UniCNS-UTF32-V.bcmap +0 -0
  131. streamlit_pdf/frontend/build/cmaps/UniCNS-UTF8-H.bcmap +0 -0
  132. streamlit_pdf/frontend/build/cmaps/UniCNS-UTF8-V.bcmap +0 -0
  133. streamlit_pdf/frontend/build/cmaps/UniGB-UCS2-H.bcmap +0 -0
  134. streamlit_pdf/frontend/build/cmaps/UniGB-UCS2-V.bcmap +0 -0
  135. streamlit_pdf/frontend/build/cmaps/UniGB-UTF16-H.bcmap +0 -0
  136. streamlit_pdf/frontend/build/cmaps/UniGB-UTF16-V.bcmap +0 -0
  137. streamlit_pdf/frontend/build/cmaps/UniGB-UTF32-H.bcmap +0 -0
  138. streamlit_pdf/frontend/build/cmaps/UniGB-UTF32-V.bcmap +0 -0
  139. streamlit_pdf/frontend/build/cmaps/UniGB-UTF8-H.bcmap +0 -0
  140. streamlit_pdf/frontend/build/cmaps/UniGB-UTF8-V.bcmap +0 -0
  141. streamlit_pdf/frontend/build/cmaps/UniJIS-UCS2-H.bcmap +0 -0
  142. streamlit_pdf/frontend/build/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
  143. streamlit_pdf/frontend/build/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
  144. streamlit_pdf/frontend/build/cmaps/UniJIS-UCS2-V.bcmap +0 -0
  145. streamlit_pdf/frontend/build/cmaps/UniJIS-UTF16-H.bcmap +0 -0
  146. streamlit_pdf/frontend/build/cmaps/UniJIS-UTF16-V.bcmap +0 -0
  147. streamlit_pdf/frontend/build/cmaps/UniJIS-UTF32-H.bcmap +0 -0
  148. streamlit_pdf/frontend/build/cmaps/UniJIS-UTF32-V.bcmap +0 -0
  149. streamlit_pdf/frontend/build/cmaps/UniJIS-UTF8-H.bcmap +0 -0
  150. streamlit_pdf/frontend/build/cmaps/UniJIS-UTF8-V.bcmap +0 -0
  151. streamlit_pdf/frontend/build/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
  152. streamlit_pdf/frontend/build/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
  153. streamlit_pdf/frontend/build/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
  154. streamlit_pdf/frontend/build/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
  155. streamlit_pdf/frontend/build/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
  156. streamlit_pdf/frontend/build/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
  157. streamlit_pdf/frontend/build/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
  158. streamlit_pdf/frontend/build/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
  159. streamlit_pdf/frontend/build/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
  160. streamlit_pdf/frontend/build/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
  161. streamlit_pdf/frontend/build/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
  162. streamlit_pdf/frontend/build/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
  163. streamlit_pdf/frontend/build/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
  164. streamlit_pdf/frontend/build/cmaps/UniKS-UCS2-H.bcmap +0 -0
  165. streamlit_pdf/frontend/build/cmaps/UniKS-UCS2-V.bcmap +0 -0
  166. streamlit_pdf/frontend/build/cmaps/UniKS-UTF16-H.bcmap +0 -0
  167. streamlit_pdf/frontend/build/cmaps/UniKS-UTF16-V.bcmap +0 -0
  168. streamlit_pdf/frontend/build/cmaps/UniKS-UTF32-H.bcmap +0 -0
  169. streamlit_pdf/frontend/build/cmaps/UniKS-UTF32-V.bcmap +0 -0
  170. streamlit_pdf/frontend/build/cmaps/UniKS-UTF8-H.bcmap +0 -0
  171. streamlit_pdf/frontend/build/cmaps/UniKS-UTF8-V.bcmap +0 -0
  172. streamlit_pdf/frontend/build/cmaps/V.bcmap +0 -0
  173. streamlit_pdf/frontend/build/cmaps/WP-Symbol.bcmap +0 -0
  174. streamlit_pdf/frontend/build/index.html +45 -0
  175. streamlit_pdf/frontend/build/standard_fonts/FoxitDingbats.pfb +0 -0
  176. streamlit_pdf/frontend/build/standard_fonts/FoxitFixed.pfb +0 -0
  177. streamlit_pdf/frontend/build/standard_fonts/FoxitFixedBold.pfb +0 -0
  178. streamlit_pdf/frontend/build/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
  179. streamlit_pdf/frontend/build/standard_fonts/FoxitFixedItalic.pfb +0 -0
  180. streamlit_pdf/frontend/build/standard_fonts/FoxitSerif.pfb +0 -0
  181. streamlit_pdf/frontend/build/standard_fonts/FoxitSerifBold.pfb +0 -0
  182. streamlit_pdf/frontend/build/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
  183. streamlit_pdf/frontend/build/standard_fonts/FoxitSerifItalic.pfb +0 -0
  184. streamlit_pdf/frontend/build/standard_fonts/FoxitSymbol.pfb +0 -0
  185. streamlit_pdf/frontend/build/standard_fonts/LICENSE_FOXIT +27 -0
  186. streamlit_pdf/frontend/build/standard_fonts/LICENSE_LIBERATION +102 -0
  187. streamlit_pdf/frontend/build/standard_fonts/LiberationSans-Bold.ttf +0 -0
  188. streamlit_pdf/frontend/build/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
  189. streamlit_pdf/frontend/build/standard_fonts/LiberationSans-Italic.ttf +0 -0
  190. streamlit_pdf/frontend/build/standard_fonts/LiberationSans-Regular.ttf +0 -0
  191. streamlit_pdf/frontend/build/workers/pdf.worker.min.mjs +29 -0
  192. streamlit_pdf/frontend/index.html +44 -0
  193. streamlit_pdf-1.0.5.dist-info/METADATA +147 -0
  194. streamlit_pdf-1.0.5.dist-info/RECORD +198 -0
  195. streamlit_pdf-1.0.5.dist-info/WHEEL +5 -0
  196. streamlit_pdf-1.0.5.dist-info/licenses/LICENSE +174 -0
  197. streamlit_pdf-1.0.5.dist-info/licenses/NOTICES +4180 -0
  198. 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,5 @@
1
+ # PDF.js Assets (copied from node_modules/pdfjs-dist at build time)
2
+ workers/
3
+ cmaps/
4
+ standard_fonts/
5
+
@@ -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}