diff --git a/scripts/README.md b/scripts/README.md index d9a3854..0a12b70 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,4 +1,4 @@ -This directory contains all the scripts in the repo. +This directory contains all the scripts in the repo. ## Contents 1. [Guidelines](#guidelines) @@ -33,4 +33,7 @@ Your contribution should update this README with the following information, and - tictactoe
A cli-based tictactoe game to play with the computer.
[Rounak Vyas](http://www.github.com/itsron717) +- pdf_merger
+ A pdf merger to combine multiple PDFs into a single PDF.
+ [Anshul Hajare](https://github.com/AnshulH) diff --git a/scripts/pdf_merger/README.md b/scripts/pdf_merger/README.md new file mode 100644 index 0000000..bd08629 --- /dev/null +++ b/scripts/pdf_merger/README.md @@ -0,0 +1,13 @@ +# PDF Merger +A python script to merge multiple pdfs into a single pdf.
+Supports only Python 3.x and Unix Based OS. + +## Usage +``` +$ pip3 install PyPDF2 +``` + +``` +$ python main.py pdf1.pdf pdf2.pdf pdf3.pdf ... +``` +> the PDFs are merged into a single PDF called merged_pdf.pdf diff --git a/scripts/pdf_merger/main.py b/scripts/pdf_merger/main.py new file mode 100644 index 0000000..5090ef1 --- /dev/null +++ b/scripts/pdf_merger/main.py @@ -0,0 +1,31 @@ +import argparse +import os +import PyPDF2 + +parser = argparse.ArgumentParser() +parser.add_argument('--paths', nargs='*', help='PDF paths') +args = parser.parse_args() +# print(args.paths) + + +def PDFmerge(pdfs, output): + + pdfMerger = [] + pdfWriter = PyPDF2.PdfFileWriter() + + for pdf in pdfs: + pdfMerger.append(pdf) + for file in pdfMerger: + pdfFileobj = open(file, 'rb') + pdfReader = PyPDF2.PdfFileReader(pdfFileobj) + for page in range(pdfReader.numPages): + pageObj = pdfReader.getPage(page) + pdfWriter.addPage(pageObj) + pdfOutput = open(output, 'wb') + pdfWriter.write(pdfOutput) + print('Merged Successfully') + + +if __name__ == "__main__": + output = 'merged_pdf.pdf' + PDFmerge(args.paths, output)