lfoppiano / streamlit-pdf-viewer

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

Component Error message on browser when trying to display a pdf #26

Closed Odrec closed 4 months ago

Odrec commented 4 months ago

I'm getting this error on my browser when trying to display a pdf (any)

Component Error
Message: TypeError: Cannot read properties of null (reading 'length')

This is my code:

from streamlit_pdf_viewer import pdf_viewer

container_pdf, container_chat = st.columns([50, 50])

with container_pdf:
    pdf_file = st.file_uploader("Upload PDF file", type=('pdf'))

    if pdf_file:
        binary_data = pdf_file.getvalue()
        pdf_viewer(input=binary_data,
                   width=700)

I tried one of the PDFs on the app here and the display works fine so it's not the PDF.

I'm using: python==3.12 streamlit==1.31.0

lfoppiano commented 4 months ago

Hi @Odrec, which version of streamlit-pdf-viewer are you using in your application?

If you call the pdf-viewer with the additional optionrendering=legacy_iframe could you see the PDF document?

Odrec commented 4 months ago

Hi @lfoppiano

The version I'm using is the latest:

streamlit-pdf-viewer==0.0.6.

I tried using that option you suggested but I get the same error. I managed to display the pdf like this with no issue:

        binary_data = pdf_file.getvalue()
        base64_pdf = base64.b64encode(binary_data).decode('utf-8')

        # Embed PDF in HTML
        pdf_display = (F'<iframe src="data:application/pdf;base64,{base64_pdf}" '
                       F'width="100%" height="1000" type="application/pdf"></iframe>')

        # Display file
        st.markdown(pdf_display, unsafe_allow_html=True)
lfoppiano commented 4 months ago

I think I found one problem, but the error message I received is different from yours. Could you update to version 0.0.7 and let me know if your code works?

Odrec commented 4 months ago

I think I found one problem, but the error message I received is different from yours. Could you update to version 0.0.7 and let me know if your code works?

It works now with the latest version :)

lfoppiano commented 4 months ago

I'm going to close this issue. Feel free to reopen or comment, if needed.