Merge only the first page of many pdfs files with Python

This is a script to merge just the first page of different pdf with PyPDF2.

import os
from PyPDF2 import PdfFileMerger

# list of pdf
x = [a for a in os.listdir() if a.endswith(".pdf")]

# merger object
merger = PdfFileMerger()

# add all file in the list to the merger object
for pdf in x:
    merger.append(open(pdf, 'rb'), pages=(0,1))

# writes the merger object in the new file
with open("result.pdf", "wb") as fout:
    merger.write(fout)

Merge everything

Go here

Merge word documents into one pdf

Go here

Append a text to a pdf

Go here


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.