#!/usr/bin/python # -*- coding: utf-8 -*- # (c) 2006 Simon Budig import sys, os, cgi, string, re, reportlab.pdfgen.canvas cm = 72 / 2.54 def draw_graphics (canvas, rn, fb, fg, txt): # Setup... # etwas kleiner als A4. canvas.setPageSize ((19*cm, 27.7*cm)) canvas.setDash (()) canvas.setLineCap (0) canvas.setStrokeColor ((0, 0, 0)) canvas.setLineWidth (0.5) canvas.setLineJoin (0) # ok, das Schild etwas hin- und herschubsen, damit # es ohne Umstände auf A4 ausgedruckt werden kann. canvas.translate (595, 0) canvas.rotate (90) canvas.translate (-32, 5) line = canvas.beginPath () line.moveTo (142, 170) line.lineTo (142, 135) line.moveTo (127, 185) line.lineTo (92, 185) line.moveTo (709, 170) line.lineTo (709, 135) line.moveTo (724, 185) line.lineTo (759, 185) line.moveTo (142, 470) line.lineTo (142, 505) line.moveTo (127, 455) line.lineTo (92, 455) line.moveTo (709, 470) line.lineTo (709, 505) line.moveTo (724, 455) line.lineTo (759, 455) canvas.drawPath (line, True, False) # Raumnummer if rn: canvas.setFillColor ((0, 0, 0)) canvas.setFont ('Helvetica', 36) canvas.drawCentredString (264, 384, rn) canvas.setLineWidth (2.835) canvas.rect (174, 369, 180, 56) # Fachbereich, Fachgruppe if fb: canvas.setFillColor ((0.255, 0.412, 0.882)) canvas.setFont ('Helvetica-Oblique', 36) canvas.drawString (378, 384, fb) if fg: num_lines = len (fg) canvas.setFillColor ((0,0,0)) if num_lines == 1: canvas.setFont ('Helvetica', 16) canvas.drawRightString (678, 384, fg[0]) else: canvas.setFont ('Helvetica', 15) canvas.drawRightString (678, 400, fg[0]) canvas.drawRightString (678, 382, fg[1]) canvas.setStrokeColor ((0.255, 0.412, 0.882)) line = canvas.beginPath () line.moveTo (369, 369) line.lineTo (680, 369) canvas.drawPath (line, True, True) # Textzeilen if txt: num_lines = len (txt) canvas.setFillColor ((0, 0, 0)) canvas.setFont ('Helvetica', 30) if num_lines == 1: canvas.drawString (188, 298, txt[0]) elif num_lines == 2: canvas.drawString (188, 313, txt[0]) canvas.drawString (188, 265, txt[1]) else: canvas.setFont ('Helvetica', 25) canvas.drawString (188, 326, txt[0]) canvas.drawString (188, 286, txt[1]) canvas.drawString (188, 246, txt[2]) # Footer canvas.setStrokeColor ((0.000, 0.000, 0.000)) canvas.setLineWidth (1) line = canvas.beginPath () line.moveTo (174, 212) line.lineTo (479, 212) canvas.drawPath (line, True, False) canvas.setFillColor ((0,0,0)) canvas.setFont ('Helvetica-Bold', 14) canvas.drawString (490, 212, 'UNIVERSITÄT SIEGEN') # Uni-U logo = canvas.beginPath () logo.moveTo (667.782, 210.421) logo.curveTo (667.782, 210.290, 667.782, 208.732, 667.782, 208.732) logo.curveTo (667.782, 208.732, 678.160, 208.732, 678.160, 208.732) logo.curveTo (678.160, 208.732, 678.160, 226.815, 678.160, 226.815) logo.curveTo (678.160, 226.815, 680.315, 225.248, 680.315, 225.248) logo.curveTo (680.315, 225.248, 680.315, 229.556, 680.315, 229.556) logo.curveTo (680.315, 229.556, 672.873, 235.562, 672.873, 235.562) logo.curveTo (672.873, 235.562, 665.692, 229.556, 665.692, 229.556) logo.curveTo (665.692, 229.556, 665.692, 225.248, 665.692, 225.248) logo.curveTo (665.692, 225.248, 667.782, 226.815, 667.782, 226.815) logo.curveTo (667.782, 226.815, 667.782, 216.174, 667.782, 216.174) logo.curveTo (667.782, 215.097, 666.480, 214.020, 665.235, 214.020) logo.curveTo (663.991, 214.020, 662.494, 214.786, 662.494, 216.174) logo.curveTo (662.494, 216.174, 662.494, 226.815, 662.494, 226.815) logo.curveTo (662.494, 226.815, 651.787, 226.815, 651.787, 226.815) logo.curveTo (651.787, 226.815, 651.787, 218.002, 651.787, 216.500) logo.curveTo (651.787, 212.213, 656.204, 208.732, 661.645, 208.732) logo.curveTo (663.939, 208.732, 666.106, 209.384, 667.782, 210.421) logo.close () canvas.drawPath (logo, False, True) if __name__ == '__main__': if os.environ.has_key ("QUERY_STRING"): sys.stderr = sys.stdout outfile = sys.stdout else: os.environ["QUERY_STRING"] = "rn=A-8103&fb=FB+12&fg=Programmiersprachen&txt=Wiss.+Mitarbeiter%0aDipl.-Math.+Simon+Budig" outfile = None items = cgi.FieldStorage() raumnummer = "" fachbereich = "" fachgruppe = "" haupttext = "" if items.has_key ("rn"): raumnummer = str (items["rn"].value) if items.has_key ("fb"): fachbereich = str (items["fb"].value) if items.has_key ("fg"): fachgruppe = filter (None, map (string.strip, string.split (str (items["fg"].value), "\n"))) if items.has_key ("txt"): haupttext = filter (None, map (string.strip, string.split (str (items["txt"].value), "\n"))) filename = string.join (["tuerschild"] + re.findall ("[a-zA-Z0-9]+", raumnummer), "-") if outfile: print "Content-Type: application/pdf" print "Content-Disposition: attachment; filename=\"%s.pdf\"\n" % filename else: outfile = file (filename + ".pdf", "w") canvas = reportlab.pdfgen.canvas.Canvas (outfile) draw_graphics (canvas, raumnummer, fachbereich, fachgruppe, haupttext) canvas.showPage () canvas.save ()