Create a streamlit app which allows the user to upload a PDF file, and then be able to download the PDF pages as separate PNG files.
Expected behavior:
Upload the PDF file, hit continue, PDF pages appear as images within the app, button to download each page appears above each image
Actual behavior:
Upload the PDF file, hit continue, first PDF page appears as image and then error. RuntimeError: Invalid binary data format: <class 'PIL.PpmImagePlugin.PpmImageFile'>
Also included below. I have managed to download the ‘image’ once, but it doesn’t open as an image, comes through as an invalid format?
import streamlit as st
import pdf2image
import zipfile
import os
pdf_uploaded = st.file_uploader("Select a file", type="pdf")
button = st.button("Confirm")
image_down = []
if button and pdf_uploaded is not None:
if pdf_uploaded.type == "application/pdf":
images = pdf2image.convert_from_bytes(pdf_uploaded.read(), poppler_path="poppler/library/bin")
for i, page in enumerate(images):
st.image(page, use_column_width=True)
st.download_button("Download", data=page, file_name=f"Image_{i}.png")
image_down.append(page)