def go(): #create the basic page and frames doc = BaseDocTemplate("phello.pdf", leftMargin=10, rightMargin=0, topMargin=0, bottomMargin=0) doc.pagesize = landscape(A4) frameCount = 2 frameWidth = doc.height / frameCount frameHeight = doc.width - .05 * inch frames = [] #construct a frame for each column for frame in range(frameCount): leftMargin = doc.leftMargin + frame * frameWidth column = Frame(leftMargin, doc.bottomMargin, frameWidth, frameHeight) print leftMargin, doc.bottomMargin, frameWidth, frameHeight frames.append(column) template = PageTemplate(frames=frames) doc.addPageTemplates(template) # doc = SimpleDocTemplate("phello.pdf", id='TwoColumns') # doc.pagesize = landscape(A4) ## TODO: make configurable Story = [] style = styles["Normal"] style.fontName = 'Courier' style.fontSize = 6 for monkey in monkeys: p = Preformatted(get_ttview(monkey[0], monkey[1], 15), style) Story.append(KeepTogether(p)) Story.append(Spacer(1, 0.05 * inch)) doc.build(Story)
F = Frame( 0, 0, width * mm, height * mm, leftPadding=.5 * inch, bottomPadding=.5 * inch, rightPadding=.5 * inch, topPadding=.5 * inch, ) PT = PageTemplate(id="calendar", frames=[ F, ]) doc = BaseDocTemplate("biocal_%4u–%02u–%02u_%u.pdf" % (by, bm, bd, year)) doc.pagesize = landscape(A4) doc.addPageTemplates([ PT, ]) doc.title = "%u biorhythm calendar for %4u–%02u–%02u" % (year, by, bm, bd) elements = [] dnamelist = 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' mnamelist = [[ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]] data = list(mnamelist) wa = (((1, 12, 13), (7, 18)), ((1, 15), (8, 22)), ((1, 17, 18), (9, 26)))
by, bm, bd = 1990, 1, 1 width, height = A4[1] * 127 / 360, A4[0] * 127 / 360 # A4 landscape frame, # converted from points to mm pagesize = (width * mm, height * mm) F=Frame(0, 0, width * mm, height * mm, leftPadding = .5 * inch, bottomPadding = .5 * inch, rightPadding = .5 * inch, topPadding = .5 * inch,) PT = PageTemplate(id = "calendar", frames = [F,]) doc = BaseDocTemplate("biocal_%4u–%02u–%02u_%u.pdf" % (by, bm, bd, year)) doc.pagesize = landscape(A4) doc.addPageTemplates([PT,]) doc.title = "%u biorhythm calendar for %4u–%02u–%02u" % (year, by, bm, bd) elements = [] dnamelist = 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' mnamelist = [['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']] data = list(mnamelist) wa=( ((1,12,13),(7,18)), ((1,15),(8,22)), ((1,17,18),(9,26)) )
def printInforme(request, numero): response = HttpResponse(content_type='application/pdf') response[ 'Content-Disposition'] = 'attachment; filename="equipoInforme.pdf"' buff = BytesIO() doc = BaseDocTemplate( buff, pagesize=A4, rightMargin=5, leftMargin=50, topMargin=250, bottomMargin=5, ) doc.pagesize = landscape(A4) equipos = [] lista_equipos = Equipo.objects.all() lista_informe = [] for equipo in lista_equipos: lista_informe.append( InformeEquipo( equipo.usuario.username, puntos_jornada_equipo(numero, equipo.usuario.username))) for equipo in lista_informe: headings = (equipo.equipo, '') dinero_total = 0 puntos_totales = 0 for p in equipo.alineacion: dinero_total = dinero_total + p.precio puntos_totales = puntos_totales + p.puntos dinero_equipo = Equipo.objects.filter(usuario__username=equipo.equipo) dinero_total = dinero_equipo[0].dinero - dinero_total allpuntos = [(p.nombre, p.puntos) for p in equipo.alineacion] footer = ('Dinero:' + str(dinero_total), str(puntos_totales)) t = Table([headings] + allpuntos + [footer], [doc.width / 6, doc.width / 20]) t.setStyle( TableStyle([('LINEAFTER', (-1, 0), (-1, -1), 1, colors.dodgerblue), ('LINEBEFORE', (0, 0), (0, -1), 1, colors.dodgerblue), ('BOX', (0, 0), (-1, 0), 2, colors.darkblue), ('BOX', (0, -1), (-1, -1), 2, colors.darkblue)])) equipos.append(t) equipos.append(Spacer(1, 0.7 * inch)) column_gap = 4.5 * cm width = doc.width / 4.5 doc.addPageTemplates([ PageTemplate(frames=[ Frame( doc.leftMargin, doc.bottomMargin, width, doc.height, id='1', rightPadding=0, showBoundary=0 # set to 1 for debugging ), Frame(doc.leftMargin + column_gap, doc.bottomMargin, width, doc.height, id='2', rightPadding=0, showBoundary=0), Frame( doc.leftMargin + (column_gap * 2), doc.bottomMargin, width, doc.height, id='3', rightPadding=0, showBoundary=0 # set to 1 for debugging ), Frame(doc.leftMargin + (column_gap * 3), doc.bottomMargin, width, doc.height, id='4', rightPadding=0, showBoundary=0), Frame( doc.leftMargin + (column_gap * 4), doc.bottomMargin, width, doc.height, id='5', rightPadding=0, showBoundary=0 # set to 1 for debugging ), Frame( doc.leftMargin + (column_gap * 5), doc.bottomMargin, width, doc.height, id='6', rightPadding=0, showBoundary=0 # set to 1 for debugging ), ]), ]) doc.build(equipos) response.write(buff.getvalue()) buff.close() return response