Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

🐛 preview_pdf not showing updated PDF #244

Open
ollyhensby opened this issue Jan 3, 2024 · 0 comments
Open

🐛 preview_pdf not showing updated PDF #244

ollyhensby opened this issue Jan 3, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ollyhensby
Copy link
Contributor

ollyhensby commented Jan 3, 2024

Describe the bug
If a PDF file is changed whilst in a session, the new PDF is not shown. The old PDF must be cached in the browser in some way.

Expected behavior
I expect the new PDF to be shown after closing and re-opening the preview display.

Potential Solution
Convert PDF into bytes and load use base64.

from base64 import b64encode
def preview_pdf(path: pathlib.Path):
    if not isinstance(path, pathlib.PurePath):
        path = pathlib.Path(path)

    with open(path, "rb") as pdf_file:
        content_b64 = b64encode(pdf_file.read()).decode()

    return IFrame(src=f"data:application/pdf;base64,{content_b64}", width=1000, height=1000)
@ollyhensby ollyhensby added the bug Something isn't working label Jan 3, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant