title: Extract specific pages of PDF and save it with Python
body: <p>I have some sources and tried to code which extract some pages and create pdf files.
  I have a list which looks like this</p>
  <pre><code>information = [(filename1,startpage1,endpage1), (filename2, startpage2, endpage2), ...,(filename19,startpage19,endpage19)].
  </code></pre>
  <p>This is my code.</p>
  <pre class="lang-py prettyprint-override"><code>from PyPDF2 import PdfFileReader, PdfFileWriter
  
  reader = PdfFileReader(&quot;example.pdf&quot;)
  
  for page in range(reader.getNumPages() - 1):
      writer = PdfFileWriter()
      start = information[page][1]
      end = information[page][2]
      while start &lt; end:
          writer.addPage(reader.getPage(start))
          start += 1
          output_filename = &quot;{}_{}_page_{}.pdf&quot;.format(
              information[page][0], information[page][1], information[page][2]
          )
      with open(output_filename, &quot;wb&quot;) as out:
          writer.write(out)
  </code></pre>
  <p>But the output is weird.. some has nothing inside and some has just one page in it. How can I correct this?</p>