mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Added new script 'PDFsplitter'
This commit is contained in:
parent
e9e1cde1a6
commit
e4aa4ed38c
44
PDFsplitter/PDFsplitter.py
Normal file
44
PDFsplitter/PDFsplitter.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
import PyPDF2
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def split_pdf(input_pdf_path, output_folder):
|
||||||
|
# Open the PDF file
|
||||||
|
pdf_file = open(input_pdf_path, "rb")
|
||||||
|
input_pdf_name = os.path.basename(input_pdf_path).split(".")[0]
|
||||||
|
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
||||||
|
|
||||||
|
# Create the output folder if it doesn't exist
|
||||||
|
os.makedirs(output_folder, exist_ok=True)
|
||||||
|
|
||||||
|
# Loop through each page and save it as a separate PDF file
|
||||||
|
for page_num in range(len(pdf_reader.pages)):
|
||||||
|
pdf_writer = PyPDF2.PdfWriter()
|
||||||
|
pdf_writer.add_page(pdf_reader.pages[page_num])
|
||||||
|
|
||||||
|
output_pdf_path = os.path.join(
|
||||||
|
output_folder, f"{input_pdf_name}_{page_num + 1}.pdf"
|
||||||
|
)
|
||||||
|
|
||||||
|
with open(output_pdf_path, "wb") as output_pdf:
|
||||||
|
pdf_writer.write(output_pdf)
|
||||||
|
print(f"Page {page_num + 1} saved as {output_pdf_path}")
|
||||||
|
|
||||||
|
# Close the input PDF file
|
||||||
|
pdf_file.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Split a PDF file into separate pages")
|
||||||
|
parser.add_argument(
|
||||||
|
"input_pdf", help="Input PDF file path")
|
||||||
|
parser.add_argument(
|
||||||
|
"output_folder", help="Output folder path for split pages")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
input_pdf_path = args.input_pdf
|
||||||
|
output_folder = args.output_folder
|
||||||
|
|
||||||
|
split_pdf(input_pdf_path, output_folder)
|
22
PDFsplitter/README.md
Normal file
22
PDFsplitter/README.md
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
## PDFsplitter
|
||||||
|
|
||||||
|
This Python script allows you to split a PDF file into separate PDF files, one for each page. It uses the PyPDF2 library to perform the splitting.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
1. Make sure you have Python 3.x installed on your system.
|
||||||
|
|
||||||
|
2. Install the required PyPDF2 library using pip:
|
||||||
|
```pip install PyPDF2```
|
||||||
|
|
||||||
|
3. Run the script with the following command:
|
||||||
|
|
||||||
|
`python PDFsplitter.py input_pdf output_folder`
|
||||||
|
- `input_pdf`: The path to the input PDF file that you want to split.
|
||||||
|
- `output_folder`: The folder where the split PDF pages will be saved.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
To split an input PDF file named `input.pdf` into separate pages and save them in an `output_pages` folder, you can run the following command:
|
||||||
|
|
||||||
|
python PDFsplitter.py input.pdf output_pages
|
1
PDFsplitter/requirements.txt
Normal file
1
PDFsplitter/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
PyPDF2==3.0.1
|
16
README.md
16
README.md
|
@ -3,13 +3,14 @@
|
||||||
|
|
||||||
## Contents:
|
## Contents:
|
||||||
|
|
||||||
- [What is this repo?](#what-is-this-repo)
|
- [Awesome Python Scripts :sunglasses: ](#awesome-python-scripts-sunglasses----)
|
||||||
- [What do we have?](#what-do-we-have)
|
- [Contents:](#contents)
|
||||||
- [How to use?](#how-to-use)
|
- [What is this repo?](#what-is-this-repo)
|
||||||
- [Contribution Guidelines](#contributions-guidelines)
|
- [What do we have:](#what-do-we-have)
|
||||||
- [Steps required to follow before adding any script](#steps-required-to-follow-before-adding-any-script)
|
- [How to use:](#how-to-use)
|
||||||
- [Contribution Guidelines](#contributions-guidelines)
|
- [Contribution Guidelines:](#contribution-guidelines)
|
||||||
- [If you like the project](#if-you-like-the-project)
|
- [Steps required to follow before adding any script](#steps-required-to-follow-before-adding-any-script)
|
||||||
|
- [If you like the project:](#if-you-like-the-project)
|
||||||
- [Want to connect with me?](#want-to-connect-with-me)
|
- [Want to connect with me?](#want-to-connect-with-me)
|
||||||
|
|
||||||
## What is this repo?
|
## What is this repo?
|
||||||
|
@ -96,6 +97,7 @@ So far, the following projects have been integrated to this repo:
|
||||||
|[Minecraft Server in background](Minecraft_server_in_background)|[Max von Forell](https://github.com/mvforell)|
|
|[Minecraft Server in background](Minecraft_server_in_background)|[Max von Forell](https://github.com/mvforell)|
|
||||||
|[Own IP locator](Location_Of_Own_IP_Adress)|[Chris]()|
|
|[Own IP locator](Location_Of_Own_IP_Adress)|[Chris]()|
|
||||||
|[PDF2text](PDF2text)|[QuangPH](https://github.com/quangph-1686a)|
|
|[PDF2text](PDF2text)|[QuangPH](https://github.com/quangph-1686a)|
|
||||||
|
|[PDFsplitter](PDFsplitter)|[Prathamesh-Ghatole](https://github.com/Prathamesh-Ghatole)|
|
||||||
|[PX to REM](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/PX-to-REM)|[Atthaphon Urairat](https://github.com/uatthaphon) |
|
|[PX to REM](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/PX-to-REM)|[Atthaphon Urairat](https://github.com/uatthaphon) |
|
||||||
|[Pdf to AudioBook Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/PdfToAudio)|[Ayesha Gull](https://github.com/ayeshag7/)|
|
|[Pdf to AudioBook Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/PdfToAudio)|[Ayesha Gull](https://github.com/ayeshag7/)|
|
||||||
|[Plagiarism_detector](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Plagiarism_detector)|[Akshita Singhal](https://github.com/akshitasinghal4444)|
|
|[Plagiarism_detector](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Plagiarism_detector)|[Akshita Singhal](https://github.com/akshitasinghal4444)|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user