Error when tryingf to merge two slide slides


This Content is from Stack Overflow. Question asked by Will

How do you merge two slide slides saved as a PDF? Specifically, I want to know how to add a second slide to a first slide. I tried copying the code in a Python Udemy course while changing the variables names, I found one solution online that looked very, very not concise, and I glanced at a stack overflow thread that ended in there maybe not being a solution. I got an error four times when running Udemy code that one of my PDFs was corrupted and never got a slide added to another slide. The expected output is a pdf file with two slides, one from each pdf files. Here’s a very rough excerpt of my code (attached). Note, the practice presentations I tried to merge I called ~sept-1.pdf and second-page.pdf + I changed the username in the file path to eliminate my nickname.

Goal: Add the one and only slide from pdf 2 and add it to the end of pdf 1.

import modules

!pip install PyPDF4

import PyPDF4

change directory to desktop

import os


Stuff after chaging the directory to the desktop

adding to my desired PDF

f = open(‘sept-1.pdf’,’rb’)
pdf_reader = PyPDF4.PdfFileReader(f)

first_page = pdf_reader.getPage(0)

pdf_writer = PyPDF4.PdfFileWriter()


pdf_output = open(“newer.pdf”,”wb”)




This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?