import PyPDF2
f=open("test.pdf","rb")
reader=pypdf.pdfFileReader(f)
print(reader.numpages)
page_one=reader.getpage(0)
page_one.extractText()
print(page_one.extractText())
f.close()

#copy pages from pdf files
f1=open("sample1.pdf","rb")
reader_1=PyPDF2.pdfFileReader(f1)
first_file=reader_1.getpage(1)
f2=open("sample2.pdf","rb")
reader_2=PyPDF2.pdfFileReader(f2)
first_file=reader_2.getpage(1)
writer=PyPDF2.pdfFilewriter()
writer.addpage(first_file)
writer.addpage(second_file)
output=("copied pages.pdf","wb")
writer.write(output)
output.close()
f1.close()
f2.close()