title: Adding blank page to odd-paged PDF in Python
body: <p>This is a rewrite of <a href="https://stackoverflow.com/questions/14281468/how-to-insert-a-missing-page-as-blank-page-in-pdf-with-python">How to insert a &quot;missing&quot; page as blank page in PDF with Python?</a> but I am trying to do it with the <code>PdfFileWriter</code> additional methods: <code>cloneDocumentFromReader()</code> and <code>addBlankPage()</code>, because it seemed cleaner this way.</p>
  
  <p>I need to add a blank page at the end of PDF, if it contains odd number of pages, but the page count is larger than 1.</p>
  
  <p>So I am trying to do this:</p>
  
  <pre><code>from PyPDF2 import PdfFileReader, PdfFileWriter
  with open(pdffile, 'rb') as input:
      pdf=PdfFileReader(input)
      numPages=pdf.getNumPages()
      if numPages &gt; 1 and (numPages % 2 == 1):
              outPdf=PdfFileWriter()
              outPdf.cloneDocumentFromReader(pdf)
              outPdf.addBlankPage()
              outStream=file('/tmp/test.pdf','wb')
              outPdf.write(outStream)
              outStream.close()
  </code></pre>
  
  <p>The code works, but the PDF created is smaller than the original, and gives error (doesn't parse) when trying to open in Adobe Acrobat.</p>
  
  <p>Do I mix up something with how this should work? I was a bit surprised when I saw I couldn't navigate in Pdf with PdfWriter to choose where to add blank page, but I assumed, after I have cloned the document, it should have some internal "marker" at the end page?</p>