From 25301ab6ca9687d98b16cd096853b55bf7bd4b4a Mon Sep 17 00:00:00 2001 From: itsron717 Date: Tue, 6 Nov 2018 21:35:08 +0530 Subject: [PATCH 1/2] Added pdf_merger script --- scripts/README.md | 5 ++++- scripts/pdf_merger/README.md | 13 +++++++++++++ scripts/pdf_merger/main.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 scripts/pdf_merger/README.md create mode 100644 scripts/pdf_merger/main.py diff --git a/scripts/README.md b/scripts/README.md index d9a3854..d6cd212 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) From 6eb5fe10ff09a2dfae30f657da615cec53fc5719 Mon Sep 17 00:00:00 2001 From: Rounak Vyas Date: Fri, 9 Nov 2018 17:15:47 +0530 Subject: [PATCH 2/2] Fixed spacing --- scripts/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index d6cd212..0a12b70 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -34,6 +34,6 @@ Your contribution should update this README with the following information, and 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) + A pdf merger to combine multiple PDFs into a single PDF.
+ [Anshul Hajare](https://github.com/AnshulH)