├── Pdf Password Protection Using Python.ipynb └── README.md /Pdf Password Protection Using Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "finnish-encyclopedia", 7 | "metadata": {}, 8 | "outputs": [ 9 | { 10 | "name": "stdout", 11 | "output_type": "stream", 12 | "text": [ 13 | "Collecting PyPDF2\n", 14 | " Downloading PyPDF2-1.26.0.tar.gz (77 kB)\n", 15 | "Building wheels for collected packages: PyPDF2\n", 16 | " Building wheel for PyPDF2 (setup.py): started\n", 17 | " Building wheel for PyPDF2 (setup.py): finished with status 'done'\n", 18 | " Created wheel for PyPDF2: filename=PyPDF2-1.26.0-py3-none-any.whl size=61085 sha256=79a1fe32a34f60dd40c2293d783ac61fd87ab958bb3c5bed3217546cd16c7a73\n", 19 | " Stored in directory: c:\\users\\win10\\appdata\\local\\pip\\cache\\wheels\\b1\\1a\\8f\\a4c34be976825a2f7948d0fa40907598d69834f8ab5889de11\n", 20 | "Successfully built PyPDF2\n", 21 | "Installing collected packages: PyPDF2\n", 22 | "Successfully installed PyPDF2-1.26.0\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "!pip install PyPDF2" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 10, 33 | "id": "known-substance", 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "from PyPDF2 import PdfFileReader,PdfFileWriter" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 11, 43 | "id": "fifteen-globe", 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "### open the current pdf\n", 48 | "file_pdf=PdfFileReader('tickets.pdf')\n", 49 | "### Object for pdf writer\n", 50 | "out_pdf=PdfFileWriter()" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 12, 56 | "id": "altered-influence", 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "data": { 61 | "text/plain": [ 62 | "" 63 | ] 64 | }, 65 | "execution_count": 12, 66 | "metadata": {}, 67 | "output_type": "execute_result" 68 | } 69 | ], 70 | "source": [ 71 | "file_pdf" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 16, 77 | "id": "critical-technique", 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "for i in range(file_pdf.numPages):\n", 82 | " page_details=file_pdf.getPage(i)\n", 83 | " ### Add to the output page\n", 84 | " out_pdf.addPage(page_details)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 17, 90 | "id": "surrounded-chart", 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [ 94 | "password=\"Krish@123\"\n", 95 | "\n", 96 | "out_pdf.encrypt(password)" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 18, 102 | "id": "divided-horror", 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "with open(\"encryptedtickets.pdf\",\"wb\") as filename:\n", 107 | " out_pdf.write(filename)" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "id": "metric-difficulty", 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [] 117 | } 118 | ], 119 | "metadata": { 120 | "kernelspec": { 121 | "display_name": "Python 3", 122 | "language": "python", 123 | "name": "python3" 124 | }, 125 | "language_info": { 126 | "codemirror_mode": { 127 | "name": "ipython", 128 | "version": 3 129 | }, 130 | "file_extension": ".py", 131 | "mimetype": "text/x-python", 132 | "name": "python", 133 | "nbconvert_exporter": "python", 134 | "pygments_lexer": "ipython3", 135 | "version": "3.8.5" 136 | } 137 | }, 138 | "nbformat": 4, 139 | "nbformat_minor": 5 140 | } 141 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pdf-Encryption --------------------------------------------------------------------------------