Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Frame, Spacer, Image
  2. from reportlab.lib import colors
  3. from reportlab.lib.units import cm, inch
  4. from reportlab.lib.pagesizes import A3, A4, landscape, portrait
  5. from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
  6. from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
  7. from reportlab.pdfgen import canvas
  8. SXmargin = 1.5 * cm
  9. DXmargin = 1.5 * cm
  10. def printTitle():
  11. st = ParagraphStyle('Normal')
  12. st.fontSize=30
  13. title = Paragraph("TITLE", st)
  14. data = [[None, title, None, None, title, None]]
  15. titleColumnSize = (doc.pagesize[0]-(SXmargin * 2 + DXmargin * 2)) /2
  16. tbl = Table(data, [SXmargin, titleColumnSize, DXmargin, SXmargin,
  17. titleColumnSize, DXmargin],None)
  18. tbl.hAlign = 'CENTER'
  19. tbl.vAlign = 'TOP'
  20. tblStyle = TableStyle([('TEXTCOLOR',(0,0),(-1,-1),colors.black),
  21. ('VALIGN',(0,0),(-1,-1),'MIDDLE'),
  22. ('LINEBELOW',(0,0),(-1,-1),1,colors.white),
  23. ('INNERGRID',(2,0),(3,0),1,colors.black),
  24. ('INNERGRID',(0,0),(-1,-1),1,colors.black),
  25. ('BOX',(0,0),(-1,-1),1,colors.black)])
  26. tblStyle.add('BACKGROUND',(0,0),(-1,-1),colors.white)
  27. tblStyle.add('ALIGN', (1, 0), (1, 0), "CENTER")
  28. tblStyle.add('ALIGN', (4, 0), (4, 0), "CENTER")
  29. tbl.setStyle(tblStyle)
  30. return tbl
  31. pdfReportPages = "test.pdf"
  32. doc = SimpleDocTemplate(pdfReportPages, pagesize=landscape(A4))
  33. elements = []
  34. styles=getSampleStyleSheet()
  35. styleN = styles["Normal"]
  36. elements.append(printTitle())
  37. doc.build(elements)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement