title: Why am I getting "I/O operation on closed file" with PILLOW 3.1.0?
body: <p>I am attempting to convert a <code>tiff</code>  file into a <code>PDF</code> using <code>Pillow</code> and <code>PyPDF</code>. I was able to get this to work using an earlier version of <code>Pillow</code>, although I cannot which version.</p>
  
  <p>I recently upgraded to <code>Pillow 3.1.0</code>, and now I ran into issues. This is the previously working code.</p>
  
  <pre><code>import os
  import traceback
  
  from PIL import Image
  from PyPDF2 import PdfFileReader, PdfFileMerger
  
  to_merge = []
  
  with Image.open('my_tif.tif') as img:
      seeker = 0
  
      while True:
          try: 
              # temp file name for PDF
              img_pdf = 'temp_{}.pdf'.format(seeker)
  
              #seeks to next image with TIFF
              img.seek(seeker)
  
              # saves the image as a PDF
              img.save(img_pdf)
  
              seeker += 1
              to_merge.append(img_pdf)
  
          except Exception as err:
              traceback.print_exc()
              break                
  
  merger = PdfFileMerger()
  for f in to_merge:
      merger.append(PdfFileReader(f))
      os.remove(f)
  merger.write('merged.pdf')
  </code></pre>
  
  <p>Beforehand, it generated a PDF for each image within the <code>tiff</code> and then merged the PDFs together with no problem.</p>
  
  <p>After I upgraded to <code>Pillow 3.1.0</code> it loops through all of the images, but then throws a <code>ValueError</code> on the final image.</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Code/Python/tiff_to_pdf.py", line 16, in &lt;module&gt;
      img.save(img_pdf)
    File "C:\Python27\lib\site-packages\PIL\Image.py", line 1675, in save
      save_handler(self, fp, filename)
    File "C:\Python27\lib\site-packages\PIL\PdfImagePlugin.py", line 155, in _save
      im.seek(pageNumber)
    File "C:\Python27\lib\site-packages\PIL\TiffImagePlugin.py", line 930, in seek
      self._seek(max(frame, 0))  # Questionable backwards compatibility.
    File "C:\Python27\lib\site-packages\PIL\TiffImagePlugin.py", line 956, in _seek
      self.fp.seek(self._frame_pos[frame])
  ValueError: I/O operation on closed file
  </code></pre>
  
  <p>What would be the cause of the <code>ValueError</code>?</p>