Extract Pages from PDF based on search in python
You could try profiling but the code is simple enough that I think you're spending most of the time in PyPDF2 code. Two options:


You can preprocess your PDF files to store their text somewhere, which will make the search phase much faster, especially if you run multiples queries on the same PDF files
You can try another parser such as a Python 3 version of PDFMiner, or even a parser written in a faster language