slimshadow commited on
Commit
0a43da7
·
verified ·
1 Parent(s): 87ba33b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ from fpdf import FPDF
4
+ import io
5
+
6
+ # Streamlit app
7
+ st.title("Image to PDF Converter")
8
+
9
+ uploaded_files = st.file_uploader("Upload Images", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
10
+ page_numbering = st.checkbox("Enable Page Numbering")
11
+
12
+ if uploaded_files:
13
+ images = []
14
+ for file in uploaded_files:
15
+ image = Image.open(file)
16
+ images.append(image)
17
+
18
+ if st.button("Generate PDF"):
19
+ pdf = FPDF()
20
+ for i, image in enumerate(images):
21
+ image_io = io.BytesIO()
22
+ image.save(image_io, format="JPEG")
23
+ image_io.seek(0)
24
+
25
+ # Add a new page to the PDF
26
+ pdf.add_page()
27
+ pdf.image(image_io, x=10, y=10, w=pdf.w - 20)
28
+
29
+ # Add page number if enabled
30
+ if page_numbering:
31
+ pdf.set_y(-25)
32
+ pdf.set_font("Arial", size=12)
33
+ pdf.cell(0, 10, f'Page {i+1}', 0, 0, 'C')
34
+
35
+ # Add copyright text at the bottom
36
+ pdf.set_y(-15)
37
+ pdf.set_font("Arial", size=10)
38
+ pdf.cell(0, 10, '© 2024 slimshadow. All rights reserved.', 0, 0, 'C')
39
+
40
+ # Save PDF
41
+ pdf_output = io.BytesIO()
42
+ pdf.output(pdf_output)
43
+ pdf_output.seek(0)
44
+
45
+ st.download_button("Download PDF", pdf_output, "images.pdf", "application/pdf")
46
+
47
+ st.success("PDF Generated successfully!")