Spaces:
Sleeping
Sleeping
File size: 1,280 Bytes
93c008b |
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 |
import streamlit as st
from PyPDF2 import PdfReader, PdfWriter
from io import BytesIO
def remove_pdf_password(file, password):
try:
reader = PdfReader(file)
if reader.is_encrypted:
reader.decrypt(password)
writer = PdfWriter()
for page in reader.pages:
writer.add_page(page)
output = BytesIO()
writer.write(output)
output.seek(0)
return output
except Exception as e:
return str(e)
st.title("PDF Password Remover")
st.write("Upload a password-protected PDF and remove its password.")
# File upload
uploaded_file = st.file_uploader("Choose a PDF file", type=["pdf"])
password = st.text_input("Enter the PDF password", type="password")
if uploaded_file and password:
if st.button("Remove Password"):
output = remove_pdf_password(uploaded_file, password)
if isinstance(output, BytesIO):
st.success("Password removed successfully!")
st.download_button(
label="Download PDF without Password",
data=output,
file_name="unlocked_pdf.pdf",
mime="application/pdf",
)
else:
st.error(f"Error: {output}")
|