Rendering PDF on UI

Hi!

I just found a solution for the blockage on chromium-based apps :smiley:

def displayPDF(file):
    # Opening file from file path
    with open(file, "rb") as f:
        base64_pdf = base64.b64encode(f.read()).decode('utf-8')

    # Embedding PDF in HTML
    pdf_display =  f"""<embed
    class="pdfobject"
    type="application/pdf"
    title="Embedded PDF"
    src="data:application/pdf;base64,{base64_pdf}"
    style="overflow: auto; width: 100%; height: 100%;">"""

    # Displaying File
    st.markdown(pdf_display, unsafe_allow_html=True)

It makes the trick I think:

2 Likes

Many thanks.

image001.png

Hi, recently I’ve started working on a component for visualising PDF documents in streamlit.

You can find it here: GitHub - lfoppiano/streamlit-pdf-viewer: Streamlit PDF viewer.

We are looking for more feedback and testers that could help us.

1 Like

excellent. Thank you.

image001.png

Sorry this certainly doesn’t work for me (google chrome, edge)

i use GitHub - pdf2htmlEX/pdf2htmlEX: Convert PDF to HTML without losing text or format.
Took some time to install it. But it works well.

Thanks.
Do you use it from within Streamlit?
I don’t see an API.

Outlook-c3dmh2ia.png

i install and package it in docker. Here is the web app: https://chatpdf.website

1 Like

thanks. Impressive work

Outlook-c3dmh2ia.png

while this does not return any error, the pdf is simply not displayed - just blank: