title: How to add multiple lines at bottom (footer) of PDF?
body: <p><strong>I have to create PDF file in which need to add lines at bottom left like footer.</strong></p>
  
  <p>Following code is working:</p>
  
  <pre><code>import StringIO
  from reportlab.pdfgen import canvas
  import uuid
  
  def test(pdf_file_name="abc.pdf", pdf_size=(432, 648), font_details=("Times-Roman", 9)):
      # create a new PDF with Reportla 
      text_to_add = "I am writing here.."
      new_pdf = "test_%s.pdf"%(str(uuid.uuid4()))
  
      packet = StringIO.StringIO() 
      packet.seek(0)
  
      c = canvas.Canvas(pdf_file_name, pagesize = pdf_size)
      #- Get the length of text in a PDF. 
      text_len = c.stringWidth(text_to_add, font_details[0], font_details[1])
      #- take margin 20 and 20 in both axis 
      #- Adjust starting point on x axis according to  text_len
      x = pdf_size[0]-20  -  text_len
      y = 20 
      #- set font.
      c.setFont(font_details[0], font_details[1])
      #- write text,
      c.drawString(x, y, text_to_add)
  
      c.showPage()
      c.save()
      return pdf_file_name
  </code></pre>
  
  <p>Now if text have multiple lines then this is not working because length of text is greater than width of Page size. Understood.</p>
  
  <p><strong>I try with <code>Frame</code> and <code>paragraph</code> but still can not write text in correct position in a PDF</strong></p>
  
  <p>Following is code:</p>
  
  <pre><code>from reportlab.lib.pagesizes import letter
  from reportlab.lib.styles import getSampleStyleSheet
  from reportlab.platypus import BaseDocTemplate, Frame, PageTemplate, Paragraph
  
  styles = getSampleStyleSheet()
  styleN = styles['Normal']
  styleH = styles['Heading1']
  
  def footer(canvas, doc):
      canvas.saveState()
      P = Paragraph("This is a multi-line footer.  It goes on every page.  " * 10, styleN)
      w, h = P.wrap(doc.width, doc.bottomMargin)
      print "w, h:", w, h
      print "doc.leftMargin:", doc.leftMargin
      P.drawOn(canvas, 10, 30)
      canvas.restoreState()
  
  def test():
      doc = BaseDocTemplate('test.pdf', pagesize=(432, 648))
      print "doc.leftMargin:", doc.leftMargin
      print "doc.bottomMargin:", doc.bottomMargin
      print "doc.width:", doc.width  
      print "doc.height:", doc.height
      frame = Frame(10, 50, 432, 648, id='normal')
      template = PageTemplate(id='test', frames=frame, onPage=footer)
      doc.addPageTemplates([template])
  
      text = []
      for i in range(1):
          text.append(Paragraph("", styleN))
  
      doc.build(text) 
  </code></pre>
  
  <p>Not understand why size of page change, because I set <code>(432, 648)</code> but is show <code>(288.0, 504.0)</code></p>
  
  <pre><code>doc.leftMargin: 72.0
  doc.bottomMargin: 72.0
  doc.width: 288.0
  doc.height: 504.0
  </code></pre>
  
  <p>Also Frame size:</p>
  
  <pre><code>w, h: 288.0 96
  doc.leftMargin: 72.0
  </code></pre>
  
  <p>Do not know how to fix this issue.
  I refer <a href="https://www.reportlab.com/docs/reportlab-userguide.pdf">this</a> link</p>