Skip to content

Commit 7d54447

Browse files
authored
Add files via upload
1 parent 2c5d3c9 commit 7d54447

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

pdf_particular_page_remover/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## About
2+
This script allows you to delete multiple pages from a PDF of your choosing
3+
4+
### Setup Module
5+
You need the following module to run the program
6+
```
7+
pip install -m PyPDF2
8+
```
9+
10+
### Instructions
11+
12+
The user will be prompted with what details are needed for the program in the following order:<br>
13+
- Specify the file to be modified
14+
- Specify how many pages you would want to delete
15+
- Specify the page numbers of the pages to be deleted
16+
17+
Now just press enter and let the magic happen!
18+
19+
### Working Screenshot
20+
![image](https://user-images.githubusercontent.com/12183499/135718811-d6b8f18e-7722-4320-945d-d42538a84779.png)

pdf_particular_page_remover/main.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from PyPDF2 import PdfFileWriter, PdfFileReader
2+
3+
print("What is the file that you would like to modify?\n[Provide file address]")
4+
file = str(input())
5+
inputFile = PdfFileReader(file)
6+
7+
pagesToDelete = []
8+
print("How many pages do you need to delete?")
9+
n = int(input())
10+
11+
print("Enter the page numbers of the files you want to delete:\n[Enter page numbers followed by pressing 'Enter']")
12+
for i in range(0, n):
13+
givenPage = int(input()) - 1
14+
pagesToDelete.append(givenPage)
15+
16+
17+
output = PdfFileWriter()
18+
19+
for i in range(inputFile.getNumPages()):
20+
if i not in pagesToDelete:
21+
p = inputFile.getPage(i)
22+
output.addPage(p)
23+
24+
with open('output.pdf', 'wb') as f:
25+
output.write(f)
26+
27+
print("Done!")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PyPDF2==1.26.0

0 commit comments

Comments
 (0)