slimshadow commited on
Commit
742eede
·
verified ·
1 Parent(s): 43518f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -2,6 +2,7 @@ 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")
@@ -24,7 +25,7 @@ if uploaded_files:
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
 
@@ -43,10 +44,11 @@ if uploaded_files:
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)
 
50
 
51
  st.download_button("Download PDF", pdf_output, "images.pdf", "application/pdf")
52
 
 
2
  from PIL import Image
3
  from fpdf import FPDF
4
  import io
5
+ import os
6
 
7
  # Streamlit app
8
  st.title("Image to PDF Converter")
 
25
  image_io.seek(0)
26
 
27
  # Save the byte stream to a temporary file
28
+ temp_filename = f'temp_image_{i}.jpg'
29
  with open(temp_filename, 'wb') as temp_file:
30
  temp_file.write(image_io.read())
31
 
 
44
  pdf.set_font("Arial", size=10)
45
  pdf.cell(0, 10, '© 2024 slimshadow. All rights reserved.', 0, 0, 'C')
46
 
47
+ # Remove temporary file
48
+ os.remove(temp_filename)
49
+
50
+ # Get the PDF content as bytes
51
+ pdf_output = io.BytesIO(pdf.output(dest='S').encode('latin1'))
52
 
53
  st.download_button("Download PDF", pdf_output, "images.pdf", "application/pdf")
54