app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import pikepdf # Function to encrypt an existing PDF def encrypt_existing_pdf(input_pdf_path, output_pdf_path, password): try: pdf = pikepdf.open(input_pdf_path) pdf.save(output_pdf_path, encryption=pikepdf.Encryption(owner=password, user=password, R=4)) pdf.close() print(f"Encrypted PDF saved as {output_pdf_path}") except Exception as e: print(f"Error: {e}") # Example usage: encrypt_existing_pdf("sample.pdf", "example_encrypted.pdf", "secure123") |