Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/manage-height
Browse files Browse the repository at this point in the history
  • Loading branch information
lfoppiano committed Mar 19, 2024
2 parents 32d7aff + e0481fc commit f2a16d4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumpversion]
current_version = "0.0.8"
current_version = "0.0.9"
commit = "true"
tag = "true"
tag_name = "v{new_version}"
14 changes: 12 additions & 2 deletions streamlit_pdf_viewer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import json

_RELEASE = True
RENDERING_EMBED = "legacy_embed"
RENDERING_IFRAME = "legacy_iframe"
RENDERING_UNWRAP = "unwrap"

if not _RELEASE:
_component_func = components.declare_component(
Expand All @@ -22,11 +25,14 @@
)


def pdf_viewer(input: Union[str, Path, bytes], width: int = 700, height: int = None, key=None,
def pdf_viewer(input: Union[str, Path, bytes],
width: int = 700,
height: int = None,
key=None,
annotations: list = (),
pages_vertical_spacing: int = 2,
annotation_outline_size: int = 1,
rendering: str = "unwrap",
rendering: str = RENDERING_UNWRAP,
pages_to_render: List[int] = ()
):
"""
Expand Down Expand Up @@ -64,6 +70,10 @@ def pdf_viewer(input: Union[str, Path, bytes], width: int = 700, height: int = N
binary = fo.read()
else:
binary = input

if rendering == RENDERING_IFRAME or rendering == RENDERING_EMBED:
if height is None:
height = "100%"

base64_pdf = base64.b64encode(binary).decode('utf-8')
component_value = _component_func(
Expand Down
7 changes: 4 additions & 3 deletions streamlit_pdf_viewer/frontend/src/PdfViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
</div>
</div>
<div v-else-if="args.rendering==='legacy_embed'">
<embed :src="`data:application/pdf;base64,${args.binary}`" width="100%" height="700" type="application/pdf"/>
<embed :src="`data:application/pdf;base64,${args.binary}`" :width="`${args.width}`" :height="`${args.height}`" type="application/pdf"/>
</div>
<div v-else-if="args.rendering==='legacy_iframe'">
<embed :src="`data:application/pdf;base64,${args.binary}`" width="100%" height="700" type="application/pdf"/>
<embed :src="`data:application/pdf;base64,${args.binary}`" :width="`${args.width}`" :height="`${args.height}`" type="application/pdf"/>
</div>
<div v-else>
Error rendering option.
Expand Down Expand Up @@ -168,7 +168,6 @@ export default {
const setFrameHeight = () => {
Streamlit.setFrameHeight(props.args.height || totalHeight.value);
// Streamlit.setComponentReady();
};
onMounted(() => {
Expand All @@ -177,9 +176,11 @@ export default {
loadPdfs(binaryDataUrl);
}
setFrameHeight();
Streamlit.setComponentReady();
});
onUpdated(() => {
// console.log("onUpdated")
setFrameHeight();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/test_iframe_width.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_should_render_template_check_container_size(page: Page):
expect(pdf_container).to_be_visible()

b_box = pdf_container.bounding_box()
assert b_box['width'] == 700
assert b_box['width'] == 500
assert b_box['height'] > 0

pdf_viewer = iframe_frame.locator('div[id="pdfViewer"]')
Expand Down

0 comments on commit f2a16d4

Please sign in to comment.