Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support width in percentage #30

Open
lfoppiano opened this issue Feb 18, 2024 · 6 comments
Open

Support width in percentage #30

lfoppiano opened this issue Feb 18, 2024 · 6 comments
Assignees
Labels
frontend Part related to the Javascript frontend component

Comments

@lfoppiano
Copy link
Owner

As requested in https://discuss.streamlit.io/t/streamlit-pdf-viewer/57768/3

Is there a way to set the width of the displayed pdf to 100%? Something like this?

pdf_viewer(input=binary_data, width="100%", height=1000)
@lfoppiano lfoppiano changed the title Add documentation of the annotations format Support width in percentage Feb 18, 2024
@lfoppiano
Copy link
Owner Author

Some references: https://discuss.streamlit.io/t/pdf-viewer-how-to-achieve-reactive-layout/46283

@lfoppiano lfoppiano added the frontend Part related to the Javascript frontend component label Feb 21, 2024
@Odrec
Copy link

Odrec commented Feb 29, 2024

Maybe this will help you. I managed a workaround for my case where I set the width to a percentage of the screen size. I get the screen size of the device using this component: https://github.com/aghasemi/streamlit_js_eval

and then I do:

            pdf_viewer(input=self.doc_binary_data, annotations=self.annotations, height=1000,
                       width=int(self.screen_width*0.4))

t29mato added a commit that referenced this issue Mar 1, 2024
t29mato added a commit that referenced this issue Mar 1, 2024
t29mato added a commit that referenced this issue Mar 1, 2024
@Odrec
Copy link

Odrec commented Mar 1, 2024

I was trying things further and I found a better solution. The problem with using the screen width is that it works nicely if you have the browser in your device in full screen but if you resize, the PDF doesn't resize with it and remains too big. So what you really need is a width percentage relative on the size of the main component of the streamlit app or relative to the component the pdf is displayed in (column, container, etc). This library allowed that for me but be aware that is 2 years old: https://github.com/avsolatorio/streamlit-dimensions.

With this I can get the width of the main component of the streamlit app like this:

self.main_dim = st_dimensions(key="main")
and then I can use that to set the width relative to the main component size like this

pdf_viewer(input=self.doc_binary_data, annotations=self.annotations, height=1000,
                       width=int(self.main_dim['width'] * 0.4))

So now the PDF resizes nicely when I resize my browser or in a mobile app as well

@lfoppiano
Copy link
Owner Author

lfoppiano commented Mar 6, 2024

The issue seems to be related to the inner height which is not provided by streamlit (ref: #39 (comment)), this is valid also for other way of covering the whole section of the application

A couple of relevant references:

@lfoppiano lfoppiano added this to the 0.0.x milestone Apr 9, 2024
@lfoppiano
Copy link
Owner Author

So now the PDF resizes nicely when I resize my browser or in a mobile app as well

Does it resize automatically or you need to reload?

@Odrec
Copy link

Odrec commented May 12, 2024

So now the PDF resizes nicely when I resize my browser or in a mobile app as well

Does it resize automatically or you need to reload?

Each time I change something in the UI in streamlit (for example close or open side panel) the app reruns so the the width of the component where the PDF is, is recalculated and the PDF displayed with the new width. But the whole redisplaying part is a bit slow, it will be nice if it was smoother

@lfoppiano lfoppiano removed this from the 0.0.x milestone Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Part related to the Javascript frontend component
Projects
None yet
Development

No branches or pull requests

3 participants