"""A printable A4 poster with a QR code that opens the bot (for dorm walls, class boards, cafeterias). Latin text only (standard PDF fonts), so it needs no font files.""" import io from reportlab.graphics import renderPDF from reportlab.graphics.barcode.qr import QrCodeWidget from reportlab.graphics.shapes import Drawing from reportlab.lib.pagesizes import A4 from reportlab.pdfgen import canvas BLUE = (0.10, 0.30, 0.60) def make_poster_pdf(link: str, bot_username: str, channel_url: str, headline: str = "DBU Freshman Central") -> bytes: w, h = A4 buf = io.BytesIO() c = canvas.Canvas(buf, pagesize=A4) c.setTitle(headline) c.setFillColorRGB(*BLUE) c.rect(0, h - 190, w, 190, stroke=0, fill=1) # header band c.setFillColorRGB(1, 1, 1) c.setFont("Helvetica-Bold", 40) c.drawCentredString(w / 2, h - 95, headline) c.setFont("Helvetica", 18) c.drawCentredString(w / 2, h - 135, "Debre Berhan University") c.setFillColorRGB(0.1, 0.1, 0.1) c.setFont("Helvetica-Bold", 28) c.drawCentredString(w / 2, h - 255, "Free study materials, one tap away") c.setFont("Helvetica", 20) for i, line in enumerate(("Lecture slides", "Past exams", "Course modules", "Weekly student ranking")): c.drawCentredString(w / 2, h - 300 - i * 28, "- " + line + " -") qr = QrCodeWidget(link) x0, y0, x1, y1 = qr.getBounds() size = 235 drawing = Drawing(size, size, transform=[size / (x1 - x0), 0, 0, size / (y1 - y0), 0, 0]) drawing.add(qr) qx, qy = (w - size) / 2, 185 c.setFillColorRGB(1, 1, 1) c.setStrokeColorRGB(*BLUE) c.setLineWidth(3) c.roundRect(qx - 16, qy - 16, size + 32, size + 32, 14, stroke=1, fill=1) renderPDF.draw(drawing, c, qx, qy) c.setFillColorRGB(*BLUE) c.setFont("Helvetica-Bold", 24) c.drawCentredString(w / 2, 128, "Scan with your phone camera") c.setFont("Helvetica", 18) c.drawCentredString(w / 2, 98, f"or search @{bot_username} on Telegram") c.setFont("Helvetica", 14) c.drawCentredString(w / 2, 56, channel_url.replace("https://", "")) c.showPage() c.save() return buf.getvalue()