Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Demerging the pdf file #556

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file modified projects/.DS_Store
Binary file not shown.
Binary file added projects/Demerge_pdfs/.DS_Store
Binary file not shown.
Binary file added projects/Demerge_pdfs/Python.pdf
Binary file not shown.
Binary file added projects/Demerge_pdfs/Python1(270 pages).pdf
Binary file not shown.
Binary file added projects/Demerge_pdfs/Python2(270 pages): 270.pdf
Binary file not shown.
Binary file added projects/Demerge_pdfs/Python3(90 pages).pdf
Binary file not shown.
Binary file added projects/Demerge_pdfs/Python4(180 pages).pdf
Binary file not shown.
9 changes: 9 additions & 0 deletions projects/Demerge_pdfs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Demerging_pdfs
Python program to convert a large pdf file to number of different sized pdf files without any change in the large file.

# Required Libraries
PyPDF2,it can be installed by typing "pip3 install PyPDF2" on your command line

# Author Name
Darpan-Balar

40 changes: 40 additions & 0 deletions projects/Demerge_pdfs/demerging_pdfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import PyPDF2

# Note: here instead of Python.pdf you should give the whole path to the pdf if the pdf is not present in the same directory where python program is present
merged_pdf = open('Python.pdf', mode='rb')


pdf = PyPDF2.PdfFileReader(merged_pdf)

(u, ctr, x) = tuple([0]*3)
for i in range(1, pdf.numPages+1):

if u >= pdf.numPages:
print("Successfully done!")
exit(0)
name = input("Enter the name of the pdf: ")
ctr = int(input(f"Enter the number of pages for {name}: "))
u += ctr
if u > pdf.numPages:
print('Limit exceeded! ')
break

# Note: In the braces you should give the desired path of where new files should be stored
base_path = '{}.pdf'
# If you want to store the new pdfs in the same directory, then leave the braces empty
path = base_path.format(name)
f = open(path, mode='wb')
pdf_writer = PyPDF2.PdfFileWriter()

for j in range(x, x+ctr):
page = pdf.getPage(j)
pdf_writer.addPage(page)

x += ctr

pdf_writer.write(f)
f.close()


merged_pdf.close()
print("Successfully done!")
17 changes: 17 additions & 0 deletions projects/Demerge_pdfs/explanation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
yay,we have successfully demerged a "Python" book pdf containing 810 pages🥳.
Python book was demerged into 4 books: Python1,Python2,Python3,Python4
Bookname No.of pages
Python1 270
Python2 270
Python3 90
Python4 180
Total 810(270+270+90+180)

This python script was a interactive program.
It means the program when executed asks user to input and runs accordingly.
Note:
1. We should be careful while giving no.of pages as input. If the given input exceeds the limit it will yell "Limit Exceeded!".
2. We can always come out of the program if we need only some part of pdf.
Example: If we have a pdf of 400 pages and we need only first 200 pages of it in 2 different pages
then we can input for those 2 pdfs and then PRESS CMD+C(Mac) or CTRL+C(windows)