PDF Merge – With GUI V2 (Python)

A small change to yesterday’s PDF Merge with GUI. The below now asks the user how many PDFs they want to merge, and then loops through the process until that many PDFs are merged into one PDF.

# geektechstuff

# libraries to import
from tkinter import *
from tkinter import filedialog
import PyPDF2

# defining variables
pdfWriter = PyPDF2.PdfFileWriter()

# creates Tk window
root = Tk()

# asks user how many PDFs to merge
number_to_merge = input('How may files to merge?: ')
number_to_merge = int(number_to_merge)

# asks users where the PDFs are
for x in range(number_to_merge):
    pdf_to_merge = filedialog.askopenfilename()

# Ask user for the name to save the file as
userfilename = filedialog.asksaveasfilename()

# loop through all PDFs
for filename in pdf2merge:
    # rb for read binary
    pdfFileObj = open(filename, 'rb')
    pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
    # Opening each page of the PDF
    for pageNum in range(pdfReader.numPages):
        pageObj = pdfReader.getPage(pageNum)
# save PDF to file, wb for write binary
pdfOutput = open(userfilename + '.pdf', 'wb')
# Outputting the PDF
# Closing the PDF writer
# closes Tk window


PDF Merge GUI V2

One thought on “PDF Merge – With GUI V2 (Python)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.