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

Add possibility to open PDF at a specific page #47

Open
solita-tsjoberg opened this issue Apr 26, 2024 · 5 comments
Open

Add possibility to open PDF at a specific page #47

solita-tsjoberg opened this issue Apr 26, 2024 · 5 comments
Labels
frontend Part related to the Javascript frontend component implemented

Comments

@solita-tsjoberg
Copy link

As stated in the title, I would love the feature to be able to open the full PDFs at a specific page.

In my usecase we settled on filtering out the specific page we wanted to open at, but opening at the right page would be much smoother.

@lfoppiano
Copy link
Owner

Thanks! Opening the PDF at a specific page would come a very handy feature. However, my experience with streamlit is not deep and moving to a specific page means scrolling down the PDF to a certain place. I'm currently not sure how this could or should be implemented, but I'm happy to follow suggestions.

@lfoppiano lfoppiano added help wanted Extra attention is needed frontend Part related to the Javascript frontend component labels Apr 29, 2024
@solita-tsjoberg
Copy link
Author

Have not delved too deep into your code, but before swapping to your code we used something like this:

import base64
import streamlit as st
import fitz

if __name__ == "__main__":
    file = fitz.open(file, filetype="pdf")
    file = file.write()
    base64_pdf = base64.b64encode(file).decode("utf-8")
    st.markdown(
        f'<iframe src="data:application/pdf;base64,{base64_pdf}#page={page_number}" type="application/pdf"></iframe>',
    )

        )

Where we used the #page=page_number that seems to be part of some standard pdf string.
This would not require any scrolling if you use this kind of string somewhere!

@lfoppiano
Copy link
Owner

Thanks!

@solita-tsjoberg are you using the rendering=legacy_iframe or legacy_embed?

We could easily add this parameter to it, but this method works only on a small subset of browsers when used by a separate component.
In fact, I was thinking to remove it completely at some point, but it seems it's still used more than I though. 🤔

@solita-tsjoberg
Copy link
Author

Neither, we are using the default unwrap rendering.

@lfoppiano
Copy link
Owner

@solita-tsjoberg the version 0.0.18-dev0 should have what you need using the unwrap rendering.

Please see here, and here for more details.

@lfoppiano lfoppiano added implemented and removed help wanted Extra attention is needed labels Aug 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 implemented
Projects
None yet
Development

No branches or pull requests

2 participants