Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,14 +18,20 @@ if uploaded_files:
|
|
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 |
-
#
|
|
|
|
|
|
|
|
|
|
|
26 |
pdf.add_page()
|
27 |
-
pdf.image(
|
28 |
-
|
29 |
# Add page number if enabled
|
30 |
if page_numbering:
|
31 |
pdf.set_y(-25)
|
@@ -37,7 +43,7 @@ if uploaded_files:
|
|
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)
|
|
|
18 |
if st.button("Generate PDF"):
|
19 |
pdf = FPDF()
|
20 |
for i, image in enumerate(images):
|
21 |
+
# Save the image to a byte stream
|
22 |
image_io = io.BytesIO()
|
23 |
image.save(image_io, format="JPEG")
|
24 |
image_io.seek(0)
|
25 |
+
|
26 |
+
# Save the byte stream to a temporary file
|
27 |
+
temp_filename = f'image_{i}.jpg'
|
28 |
+
with open(temp_filename, 'wb') as temp_file:
|
29 |
+
temp_file.write(image_io.read())
|
30 |
+
|
31 |
+
# Add a new page to the PDF and insert the image
|
32 |
pdf.add_page()
|
33 |
+
pdf.image(temp_filename, x=10, y=10, w=pdf.w - 20)
|
34 |
+
|
35 |
# Add page number if enabled
|
36 |
if page_numbering:
|
37 |
pdf.set_y(-25)
|
|
|
43 |
pdf.set_font("Arial", size=10)
|
44 |
pdf.cell(0, 10, '© 2024 slimshadow. All rights reserved.', 0, 0, 'C')
|
45 |
|
46 |
+
# Save PDF to a byte stream
|
47 |
pdf_output = io.BytesIO()
|
48 |
pdf.output(pdf_output)
|
49 |
pdf_output.seek(0)
|