makesimple.py 977 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. "Make some simple multipage pdf files."
  3. from __future__ import print_function
  4. from sys import argv
  5. from reportlab.pdfgen import canvas
  6. point = 1
  7. inch = 72
  8. TEXT = """%s page %d of %d
  9. a wonderful file
  10. created with Sample_Code/makesimple.py"""
  11. def make_pdf_file(output_filename, np):
  12. title = output_filename
  13. c = canvas.Canvas(output_filename, pagesize=(8.5 * inch, 11 * inch))
  14. c.setStrokeColorRGB(0,0,0)
  15. c.setFillColorRGB(0,0,0)
  16. c.setFont("Helvetica", 12 * point)
  17. for pn in range(1, np + 1):
  18. v = 10 * inch
  19. for subtline in (TEXT % (output_filename, pn, np)).split( '\n' ):
  20. c.drawString( 1 * inch, v, subtline )
  21. v -= 12 * point
  22. c.showPage()
  23. c.save()
  24. if __name__ == "__main__":
  25. nps = [None, 5, 11, 17]
  26. for i, np in enumerate(nps):
  27. if np:
  28. filename = "simple%d.pdf" % i
  29. make_pdf_file(filename, np)
  30. print ("Wrote", filename)