app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import streamlit as st from PIL import Image from io import BytesIO st.markdown(""" <style> footer {visibility: hidden;} </style> """, unsafe_allow_html=True) # Title of the app st.title("Convert Multiple Images to PDF") # Instructions for the user st.write("Upload multiple images to convert them into a single PDF.") # File uploader for multiple image files uploaded_files = st.file_uploader("Choose images", type=["jpg", "jpeg", "png"], accept_multiple_files=True) # Button to generate and download PDF if st.button("Convert to PDF"): if uploaded_files: images = [] for uploaded_file in uploaded_files: image = Image.open(uploaded_file) # Convert image to RGB in case it’s in another mode (like RGBA) if image.mode != 'RGB': image = image.convert('RGB') images.append(image) # Convert images to a single PDF pdf_buffer = BytesIO() images[0].save(pdf_buffer, format="PDF", save_all=True, append_images=images[1:]) pdf_buffer.seek(0) # Provide download button st.download_button(label="Download PDF", data=pdf_buffer, file_name="converted_images.pdf", mime="application/pdf") else: st.warning("Please upload at least one image.") |