title: PyPDF2 split pdf by pages
body: <p>I wanna split pdf file using PyPDF2.</p>
  
  <p>All examples in net is too difficult or don't work or always give error "AttributeError: 'PdfFileWriter' object has no attribute 'stream'"</p>
  
  <p>Can someone help with it ? Need separete one pdf with 3 pages into three different files.</p>
  
  <p>I'm starting from that:</p>
  
  <pre><code>pdfFileObj = open(r"D:\BPO\act.pdf", 'rb')
  pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
  pdfWriter = PyPDF2.PdfFileWriter()
  pdfWriter.addPage(pdfReader.getPage(0))
  </code></pre>
  
  <p>But don't know what to do next :(</p>
  
  <p><strong>EDIT#1</strong></p>
  
  <p>Was try do a loop for spliting and i'm have a problem: PdfFileWriter make 3 files one with one page, second - with two, and third with three. Where is my mistake in following code:</p>
  
  <pre><code>act_sub_pages_name = ['p01.pdf', 'p02.pdf', 'p03.pdf']
  with open(r"D:\BPO\act.pdf", 'rb') as act_mls:
      reader = PdfFileReader(act_mls)
      writer = PdfFileWriter()
      if reader.numPages == 3:
          counter = 0
          for x in range(3):
              path = '\\'.join(['D:\\BPO\\act sub pages', act_sub_pages_name[counter]])
              counter += 1
              writer.addPage(reader.getPage(x))
              with open(path, 'wb') as outfile: writer.write(outfile)
  </code></pre>
  
  <p>Sry for bad English.</p>
  
  <p><strong>EDIT#2</strong></p>
  
  <p>My solution according by Paul Rooney answer:</p>
  
  <pre><code>act_pdf_file = 'D:\\BPO\\act.pdf'
  act_sub_pages_name = ['p01.pdf', 'p02.pdf', 'p03.pdf']
  
  def pdf_splitter(index, src_file):
      with open(src_file, 'rb') as act_mls:
          reader = PdfFileReader(act_mls)
          writer = PdfFileWriter()
          writer.addPage(reader.getPage(index))
          out_file = os.path.join('D:\\BPO\\act sub pages', act_sub_pages_name[index])
          with open(out_file, 'wb') as out_pdf: writer.write(out_pdf)
  
  for x in range(3): pdf_splitter(x, act_pdf_file)
  </code></pre>
  
  <p>With function all works properly but it a little bit harder.</p>