In [1]:
import PyPDF2

In [2]:
merger = PyPDF2.PdfFileMerger()

In [3]:
merger.append('data/src/pdf/sample1.pdf', pages=(0, 1))
merger.append('data/src/pdf/sample2.pdf', pages=(2, 4))
merger.merge(2, 'data/src/pdf/sample3.pdf', pages=(0, 3, 2))

In [4]:
merger.write('data/temp/sample_merge_page.pdf')
merger.close()

In [5]:
merger = PyPDF2.PdfFileMerger()

In [6]:
merger.append('data/src/pdf/sample1.pdf', pages=PyPDF2.pagerange.PageRange('-1'))
merger.append('data/src/pdf/sample2.pdf', pages=PyPDF2.pagerange.PageRange('2:'))
merger.merge(2, 'data/src/pdf/sample3.pdf', pages=PyPDF2.pagerange.PageRange('::-1'))

In [7]:
merger.write('data/temp/sample_merge_pagerange.pdf')
merger.close()

In [8]:
reader1 = PyPDF2.PdfFileReader('data/src/pdf/sample1.pdf')
reader2 = PyPDF2.PdfFileReader('data/src/pdf/sample2.pdf')

In [9]:
writer = PyPDF2.PdfFileWriter()

In [10]:
writer.addPage(reader1.getPage(0))
writer.addPage(reader2.getPage(2))

In [11]:
with open('data/temp/sample_merge_wr.pdf', 'wb') as f:
    writer.write(f)