Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PyPDF2 import PdfMerger
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Streamlit app layout
|
| 6 |
+
st.title("PDF Combiner App")
|
| 7 |
+
st.write("Upload individual PDF pages to combine them into one PDF document.")
|
| 8 |
+
|
| 9 |
+
uploaded_files = st.file_uploader("Upload PDF pages", type="pdf", accept_multiple_files=True)
|
| 10 |
+
|
| 11 |
+
if uploaded_files:
|
| 12 |
+
merger = PdfMerger()
|
| 13 |
+
|
| 14 |
+
for uploaded_file in uploaded_files:
|
| 15 |
+
st.write(f"Adding: {uploaded_file.name}")
|
| 16 |
+
merger.append(uploaded_file)
|
| 17 |
+
|
| 18 |
+
# Save the combined PDF to a temporary file
|
| 19 |
+
output_filename = "combined_document.pdf"
|
| 20 |
+
with open(output_filename, "wb") as output_file:
|
| 21 |
+
merger.write(output_file)
|
| 22 |
+
|
| 23 |
+
st.success("PDF pages combined successfully!")
|
| 24 |
+
|
| 25 |
+
# Provide download link
|
| 26 |
+
with open(output_filename, "rb") as f:
|
| 27 |
+
st.download_button("Download Combined PDF", f, file_name=output_filename, mime="application/pdf")
|
| 28 |
+
|
| 29 |
+
# Clean up
|
| 30 |
+
os.remove(output_filename)
|