lfoppiano / streamlit-pdf-viewer

Streamlit PDF viewer
https://structure-vision.streamlit.app/
Apache License 2.0
97 stars 6 forks source link

Viewer runs twice #70

Open MaxwellSalmon opened 4 days ago

MaxwellSalmon commented 4 days ago

Thanks for making such a great component, it's very nice!

However, I am experiencing issues, especially when viewing large PDF files, where it seems the viewer reloads once the PDF file has loaded, making the code run twice.

I tried making a simple page in my dashboard to test it. Here's the code:

from streamlit_pdf_viewer import pdf_viewer
import streamlit as st
import time

print(time.time())
pdf_viewer(st.session_state['pdf'], height=950,
            width=764,
            scroll_to_annotation=1,
            annotations=[st.session_state['annotations']],
            )
print("test")

This will print the time and "test", then the PDF is rendered. Once it is completely loaded, the statements are printed to the console again. This gets much more prominent, when scroll_to_annotation is uncluded, as it will make the whole page jump around, especially with long PDF's.

Do you have any suggestions to why this is happening or any ideas to how I can work around this?

Thanks!

lfoppiano commented 4 days ago

Hi @MaxwellSalmon, thanks for your interest in our viewer.

How big is the PDF ? How many pages?

MaxwellSalmon commented 4 days ago

Thanks for the quick response!

It's actually an issue with with both long and short documents, but most disturbing with long documents, as it takes loner to load both times.

The one I tested was +70 pages, but I have now tested with a 9-page long document, which have the same issue. The issue is also more prominent, on my main page, which features other functionalities, such as input fields.

lfoppiano commented 4 days ago

OK. Which browser and with Operating System do you use?

MaxwellSalmon commented 4 days ago

The Browser is Edge Version 129.0.2792.65 and I am running Windows 10

lfoppiano commented 4 days ago

@MaxwellSalmon I'm sorry, I haven't used it with Edge, as I don't have Windows, I cannot guarantee support for Edge. My time is limited and I wish I have a contributor helping improving the support for Windows/Edge.

Could you give it a try with Firefox, Chrome or Brave (nicer version of Chrome) and let me know whether it's working better?

MaxwellSalmon commented 4 days ago

No worries, I completely understand! I have tried it with Chrome, which gave the same issue, though I am unable to install other browsers on this PC at the moment.

Please let me know, if something changes on this topic 🙂

lfoppiano commented 4 days ago

OK, can you share a couple of PDF documents? You can send them to luca AT Sciencialab.com if they cannot be shared online.

MaxwellSalmon commented 3 days ago

I am afraid, I can't. The documents I am working with are medical documents with sensitive information. Do you suspect the PDF is to blame?

lfoppiano commented 3 days ago

Hi @MaxwellSalmon no problem, I understand. I did tried with some documents I have at hand but for me it works fine. Without reproducing the issue locally I'm not sure how to solve it 😄

@t29mato when you have some time, could you please go through the JS part and double-check that we don't refresh the page twice?