Skip to content
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
22 changes: 22 additions & 0 deletions Python/PDF_Merger/PDF_Merger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## PDF MERGER
- This is just a simple, yet useful code written in Python.
- Easy to use as well as really helpful
- Allows you to merge more than one PDF files into a single PDF.

### Instruction
- First and foremost copy and paste the code somewhere in your computer or download the PDF_Merger file
- Add all the PDF you want to convert into the [to_convert](https://github.com/4N1Z/code-n-stitch/tree/master/Python/PDF_Merger/to_convert).
- Then run the code
- The merged PDF will appear at [Converted file](https://github.com/4N1Z/code-n-stitch/tree/master/Python/PDF_Merger/converted).

## Requirements
- You should be able to run python inside your computer
> If not then refer [here](https://www.python.org/)
- Then go to your terminal and you should install PyPDF2, which is a python library.
> [Refer here](https://pypi.org/project/PyPDF2/)

#### That's it , with that you musst be able to merge your PDF's. 😄




1 change: 1 addition & 0 deletions Python/PDF_Merger/converted/note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The converted file will appear in this folder.
33 changes: 33 additions & 0 deletions Python/PDF_Merger/pdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from csv import writer
from pathlib import Path
from PyPDF2 import PdfFileMerger, PdfFileReader
import sys
import os


# Define input directory for the pdf files
pdf_dir = Path(__file__).parent / "to_convert"

# The output directory.
pdf_output_dir = Path(__file__).parent / "converted"
pdf_output_dir.mkdir(parents=True, exist_ok=True)

# To take the list of all the .pdf files
pdf_files = list(pdf_dir.glob("*.pdf"))

# Use the first 3 characters as the 'key'
keys = set([file.name[:3] for file in pdf_files])

# Determine the file name length of the base file

BASE_FILE_NAME_LENGTH = 20

for key in keys:
merger = PdfFileMerger()
for file in pdf_files:
if file.name.startswith(key):
merger.append(PdfFileReader(str(file), "rb"))
if len(file.name) >= BASE_FILE_NAME_LENGTH:
base_file_name = file.name
merger.write(str(pdf_output_dir / base_file_name))
merger.close()
1 change: 1 addition & 0 deletions Python/PDF_Merger/to_convert/note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the files you want to merge in this directory