title: Booklet page layout with ReportLab
body: <p>I have a Python program that generates a PDF file with ReportLab, and I'd like to generate another PDF that is formatted to have each page cut in half, then folded and stapled together into a booklet.</p>
  
  <p>For example, if my current document contains pages A, B, C, D, E, F, G, and H, I want the new document to have two pages that I can print double sided to come out like this:</p>
  
  <pre><code>BG|HA
  DE|FC
  </code></pre>
  
  <p>I have seen this order referred to as 4-up or imposition.</p>
  
  <p>My printer has an option for printing four pages to each sheet, but it doesn't reorder the pages. If I print the current document with that setting and double sided, it comes out like this:</p>
  
  <pre><code>AB|EF
  CD|GH
  </code></pre>
  
  <p>My first preference is to generate a PDF with four pages per sheet as shown. If I can't figure that out, the next best thing would be to generate a PDF with reordered pages so that my printer can print them four pages to each sheet. In other words, reorder the pages to B, G, D, E, H, A, F, and C.</p>
  
  <p>Here's a code example that prints eight pages:</p>
  
  <pre><code>from subprocess import call
  
  from reportlab.lib import pagesizes
  from reportlab.lib.styles import getSampleStyleSheet
  from reportlab.lib.units import inch
  from reportlab.platypus import SimpleDocTemplate, Paragraph
  
  
  def main():
      pdf_path = 'booklet.pdf'
      doc = SimpleDocTemplate(pdf_path,
                              pagesize=pagesizes.letter,
                              topMargin=0.625*inch,
                              bottomMargin=0.625*inch)
      styles = getSampleStyleSheet()
      paragraph_style = styles['Normal']
      print(paragraph_style.fontSize, paragraph_style.leading)
      paragraph_style.fontSize = 300
      paragraph_style.leading = 360
      story = []
      for text in 'ABCDEFGH':
          flowable = Paragraph(text, paragraph_style)
          story.append(flowable)
  
      doc.build(story)
  
      # call(["evince", pdf_path])  # launch PDF viewer
  
  
  main()
  </code></pre>