INTRODUCTION
The PDF_MERGER in Python is a simple tool that mixes a couple of PDF documents right into a single file. It uses the PyPDF2 library to address PDF merging, making it useful for organizing reports, documents, or study substances.
STEP 1: Import PyPDF2 Library: The software imports PyPDF2 to handle PDF merging.
import PyPDF2
STEP 2: Define Function to Merge PDFs: The merge_pdfs() function initializes a PdfMerger item and appends every PDF from the listing.
def merge_pdfs(pdf_list, output_pdf): merger = PyPDF2.PdfMerger() for pdf in pdf_list: merger.append(pdf) merger.write(output_pdf) merger.close()
STEP 3: Take User Input for PDFs: The application asks the consumer to enter the wide variety of PDFs and their filenames.
num_files = int(input("Enter the number of PDFs to merge: ")) pdf_files = [input(f"Enter PDF {i+1} filename (with .pdf extension): ") for i in range(num_files)] output_filename = input("Enter output PDF filename (with .pdf extension): ")
STEP 4: Merge PDFs: The function combines the given PDFs right into a single file.
Save and Close the Merged PDF: The software writes the merged content to the output record and closes the merger.
Display Success Message: After merging, the program prints a affirmation message with the output filename.
merge_pdfs(pdf_files, output_filename) print(f"PDFs merged successfully into {output_filename}")
OUTPUT
Enter the number of PDFs to merge: 2
Enter PDF 1 filename (with .pdf extension): file1.pdf
Enter PDF 2 filename (with .pdf extension): file2.pdf
Enter output PDF filename (with .pdf extension): merged.pdf
PDFs merged successfully into merged.pdf