22
22
)
23
23
24
24
25
- def pdf_viewer (input : Union [str , Path , bytes ], width : int = 700 , height : int = None , key = None , annotations = [],
26
- page_margin = 2 , annotation_outline_size = 1 ):
25
+ def pdf_viewer (input : Union [str , Path , bytes ], width : int = 700 , height : int = None , key = None ,
26
+ annotations = (),
27
+ pages_vertical_spacing = 2 ,
28
+ annotation_outline_size = 1
29
+ ):
27
30
"""
28
31
pdf_viewer function to display a PDF file in a Streamlit app.
29
32
@@ -32,10 +35,8 @@ def pdf_viewer(input: Union[str, Path, bytes], width: int = 700, height: int = N
32
35
:param height: Height of the PDF viewer in pixels. If not provided, the viewer show the whole content.
33
36
:param key: An optional key that uniquely identifies this component. Used to preserve state in Streamlit apps.
34
37
:param annotations: A list of annotations to be overlaid on the PDF. Each annotation should be a dictionary.
35
- :param page_margin: The margin (in pixels) between each page of the PDF. It adjusts the spacing between pages.
36
- Defaults to 2 pixels.
37
- :param annotation_outline_size: Size of the outline around each annotation in pixels.
38
- Defaults to 1 pixel.
38
+ :param pages_vertical_spacing: The vertical space (in pixels) between each page of the PDF. Defaults to 2 pixels.
39
+ :param annotation_outline_size: Size of the outline around each annotation in pixels. Defaults to 1 pixel.
39
40
40
41
The function reads the PDF file (from a file path, URL, or binary data), encodes it in base64,
41
42
and uses a Streamlit component to render it in the app. It supports optional annotations and adjustable margins.
@@ -57,7 +58,7 @@ def pdf_viewer(input: Union[str, Path, bytes], width: int = 700, height: int = N
57
58
58
59
base64_pdf = base64 .b64encode (binary ).decode ('utf-8' )
59
60
component_value = _component_func (binary = base64_pdf , width = width , height = height , key = key , default = 0 ,
60
- annotations = annotations , page_margin = page_margin ,
61
+ annotations = annotations , pages_vertical_spacing = pages_vertical_spacing ,
61
62
annotation_outline_size = annotation_outline_size )
62
63
return component_value
63
64
0 commit comments