Skip to content

Commit 37f5863

Browse files
committed
correct arguments for page vertical spacing
1 parent 7260a92 commit 37f5863

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

streamlit_pdf_viewer/__init__.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
)
2323

2424

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+
):
2730
"""
2831
pdf_viewer function to display a PDF file in a Streamlit app.
2932
@@ -32,10 +35,8 @@ def pdf_viewer(input: Union[str, Path, bytes], width: int = 700, height: int = N
3235
:param height: Height of the PDF viewer in pixels. If not provided, the viewer show the whole content.
3336
:param key: An optional key that uniquely identifies this component. Used to preserve state in Streamlit apps.
3437
: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.
3940
4041
The function reads the PDF file (from a file path, URL, or binary data), encodes it in base64,
4142
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
5758

5859
base64_pdf = base64.b64encode(binary).decode('utf-8')
5960
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,
6162
annotation_outline_size=annotation_outline_size)
6263
return component_value
6364

streamlit_pdf_viewer/frontend/src/PdfViewer.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default {
4040
const pageIndex = page - 1;
4141
let height = 0;
4242
for (let i = 0; i < pageIndex; i++) {
43-
height += Math.floor(pageHeights.value[i] * pageScales.value[i]) + props.args.page_margin; // Add margin for each page
43+
height += Math.floor(pageHeights.value[i] * pageScales.value[i]) + props.args.pages_vertical_spacing; // Add margin for each page
4444
}
4545
return height;
4646
};
@@ -73,7 +73,7 @@ export default {
7373
canvas.height = viewport.height;
7474
canvas.width = viewport.width;
7575
canvas.style.display = "block";
76-
canvas.style.marginBottom = `${props.args.page_margin}px`;
76+
canvas.style.marginBottom = `${props.args.pages_vertical_spacing}px`;
7777
return canvas;
7878
};
7979
@@ -103,11 +103,11 @@ export default {
103103
maxWidth.value = canvas.width;
104104
}
105105
totalHeight.value += canvas.height;
106-
totalHeight.value += props.args.page_margin;
106+
totalHeight.value += props.args.pages_vertical_spacing;
107107
await renderPage(page, canvas);
108108
}
109109
// Subtract the margin for the last page as it's not needed
110-
totalHeight.value -= props.args.page_margin;
110+
totalHeight.value -= props.args.pages_vertical_spacing;
111111
};
112112
113113

0 commit comments

Comments
 (0)