streamlit-pdf-viewer icon indicating copy to clipboard operation
streamlit-pdf-viewer copied to clipboard

Add possibility to open PDF at a specific page

Open solita-tsjoberg opened this issue 1 year ago • 5 comments

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.

solita-tsjoberg avatar Apr 26 '24 11:04 solita-tsjoberg

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 avatar Apr 29 '24 06:04 lfoppiano

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!

solita-tsjoberg avatar Apr 29 '24 12:04 solita-tsjoberg

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. 🤔

lfoppiano avatar Apr 29 '24 20:04 lfoppiano

Neither, we are using the default unwrap rendering.

solita-tsjoberg avatar May 06 '24 07:05 solita-tsjoberg

@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 avatar Aug 19 '24 07:08 lfoppiano