Skip to content

Commit ae5c1e3

Browse files
committed
implement % resize
1 parent 9978440 commit ae5c1e3

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ beautifulsoup4
33
lxml
44
grobid-client-python
55
watchdog
6-
streamlit-pdf-viewer==0.0.20
6+
streamlit-pdf-viewer==0.0.21-dev0

streamlit_app.py

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
if 'page_selection' not in st.session_state:
4141
st.session_state['page_selection'] = []
4242

43+
if 'size_in_pixel' not in st.session_state:
44+
st.session_state['size_in_pixel'] = None
45+
4346
st.set_page_config(
4447
page_title="Structure vision",
4548
page_icon="",
@@ -88,8 +91,14 @@
8891

8992
st.header("Height and width")
9093
resolution_boost = st.slider(label="Resolution boost", min_value=1, max_value=10, value=1)
91-
width = st.slider(label="PDF width", min_value=100, max_value=1000, value=700)
92-
height = st.slider(label="PDF height", min_value=-1, max_value=10000, value=-1)
94+
st.session_state['size_in_pixel'] = st.toggle('Size in pixels', value=True,
95+
disabled=not st.session_state['uploaded'])
96+
if st.session_state['size_in_pixel']:
97+
width = st.slider(label="PDF width", min_value=100, max_value=1000, value=700)
98+
height = st.slider(label="PDF height", min_value=-1, max_value=10000, value=-1)
99+
else:
100+
width = st.slider(label="PDF width", min_value=-1, max_value=100, value=100)
101+
width = str(width) + "%"
93102

94103
st.header("Page Selection")
95104
placeholder = st.empty()
@@ -154,6 +163,7 @@ def init_grobid():
154163
'affiliation': 'Affiliation'
155164
}
156165

166+
157167
def my_custom_annotation_handler(annotation):
158168
output_json = {
159169
"Index": annotation['index'],
@@ -163,6 +173,7 @@ def my_custom_annotation_handler(annotation):
163173

164174
annotations_component.json(output_json)
165175

176+
166177
def get_file_hash(fname):
167178
hash_md5 = blake2b()
168179
with open(fname, "rb") as f:
@@ -245,19 +256,33 @@ def get_file_hash(fname):
245256
if not highlight_affiliations:
246257
annotations = list(filter(lambda a: a['type'] != 'affiliation', annotations))
247258

248-
if height > -1:
249-
pdf_viewer(
250-
input=st.session_state['binary'],
251-
width=width,
252-
height=height,
253-
annotations=annotations,
254-
pages_vertical_spacing=pages_vertical_spacing,
255-
annotation_outline_size=annotation_thickness,
256-
pages_to_render=st.session_state['page_selection'],
257-
render_text=enable_text,
258-
resolution_boost=resolution_boost,
259-
on_annotation_click=my_custom_annotation_handler
260-
)
259+
if st.session_state['size_in_pixel']:
260+
if height > -1:
261+
pdf_viewer(
262+
input=st.session_state['binary'],
263+
width=width,
264+
height=height,
265+
annotations=annotations,
266+
pages_vertical_spacing=pages_vertical_spacing,
267+
annotation_outline_size=annotation_thickness,
268+
pages_to_render=st.session_state['page_selection'],
269+
render_text=enable_text,
270+
resolution_boost=resolution_boost,
271+
on_annotation_click=my_custom_annotation_handler
272+
)
273+
else:
274+
pdf_viewer(
275+
input=st.session_state['binary'],
276+
width=width,
277+
annotations=annotations,
278+
pages_vertical_spacing=pages_vertical_spacing,
279+
annotation_outline_size=annotation_thickness,
280+
pages_to_render=st.session_state['page_selection'],
281+
render_text=enable_text,
282+
resolution_boost=resolution_boost,
283+
on_annotation_click=my_custom_annotation_handler
284+
)
285+
261286
else:
262287
pdf_viewer(
263288
input=st.session_state['binary'],

0 commit comments

Comments
 (0)