def create_pdf(): I = Image('qr1.png') I.drawHeight = 18 * mm * I.drawHeight / I.drawWidth I.drawWidth = 18 * mm qr1 = genQR('hahahahah') # Create a frame CatBox_frame = Frame( x1=0 * mm, # From left y1=0 * mm, # From bottom height=75 * mm, width=110 * mm, leftPadding=0 * mm, bottomPadding=0 * mm, rightPadding=0 * mm, topPadding=0 * mm, showBoundary=1, id='CatBox_frame') table_data = [[qr1, qr1, qr1], [qr1, qr1, qr1], [qr1, qr1, qr1]] table_data2 = [] qrcode_valarr = genNum() arrindex = 0 for i in range(0, 3): t1 = [] for j in range(0, 3): qr1 = genQR(qrcode_valarr[arrindex]) arrindex = arrindex + 1 t1.append(qr1) table_data2.append(t1) # Create a table CatBox = Table(table_data2, 36.6 * mm, 25 * mm, vAlign='BOTTOM') # Style the table CatBox.setStyle( TableStyle([('ALIGN', (0, 0), (-1, -1), 'CENTER'), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE')])) # Trying to tell the table to be a bottom align object (when later put in frame) CatBox.Align = 'BOTTOM' CatBox.vAlign = 'BOTTOM' # Building the story #story = [CatBox] # adding CatBox table (alternative, story.add(CatBox)) story = [TopPadder(CatBox)] # Establish a document doc = BaseDocTemplate("DanhSach_QRCode.pdf", pagesize=QRCode) # Creating a page template frontpage = PageTemplate(id='FrontPage', frames=[CatBox_frame]) # Adding the story to the template and template to the document doc.addPageTemplates(frontpage) # Building doc doc.build(story)
def create_pdf(): I = Image('qr1.png') I.drawHeight = 22*mm*I.drawHeight / I.drawWidth I.drawWidth = 22*mm # Create a frame CatBox_frame = Frame( x1=0 * mm, # From left y1=0 * mm, # From bottom height=75 * mm, width=110 * mm, leftPadding=0 * mm, bottomPadding=0 * mm, rightPadding=0 * mm, topPadding=0 * mm, showBoundary=1, id='CatBox_frame') table_data=[[[I], [I], [I]], [[I], [I], [I]], [[I], [I], [I]]] # Create a table CatBox = Table(table_data, 36.6* mm, 25 * mm, vAlign='BOTTOM') # Style the table CatBox.setStyle(TableStyle( [('ALIGN',(0,0),(-1,-1),'CENTER'), ('VALIGN',(0,0),(-1,-1),'MIDDLE') ])) # Trying to tell the table to be a bottom align object (when later put in frame) CatBox.Align = 'BOTTOM' CatBox.vAlign = 'BOTTOM' # Building the story #story = [CatBox] # adding CatBox table (alternative, story.add(CatBox)) story = [TopPadder(CatBox)] # Establish a document doc = BaseDocTemplate("BottomAlignTable.pdf", pagesize=QRCode) # Creating a page template frontpage = PageTemplate(id='FrontPage', frames=[CatBox_frame] ) # Adding the story to the template and template to the document doc.addPageTemplates(frontpage) # Building doc doc.build(story)
def ScheduleReport(request): if request.method == 'POST': periodo = request.POST['selectPeriodo'] docente = request.POST['selectDocente'] response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'filename="Reporte_Horarios.pdf"' styles = getSampleStyleSheet() styleN = styles["BodyText"] styleN.alignment = TA_LEFT styleN.fontSize = 6.2 styleBH = styles["Normal"] styleBH.alignment = TA_CENTER styleBH.fontSize = 10 styleBH.color = colors.white img = (Image('static/images/sicolab_carr.png', width=25 * cm, height=4.7 * cm)) hora = Paragraph("\nHora\n", styleBH) lunes = Paragraph("\nLunes\n", styleBH) martes = Paragraph("\nMartes\n", styleBH) miercoles = Paragraph("\nMiércoles\n", styleBH) jueves = Paragraph("\nJueves\n", styleBH) viernes = Paragraph("\nViernes\n", styleBH) arr_i = [ "07:00:00", "08:00:00", "09:00:00", "10:00:00", "11:00:00", "12:00:00" ] arr_f = [ "08:00:00", "09:00:00", "10:00:00", "11:00:00", "12:00:00", "13:00:00" ] estilos_tabla = [ ('GRID', (0, 1), (-1, -1), 0.5, colors.transparent), ('BOX', (0, 0), (-1, -1), 2, colors.gray), ('BACKGROUND', (0, 0), (12, 0), colors.lightblue), ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black), ('FONTSIZE', (0, 0), (-1, 0), 12), ('FONTSIZE', (0, 1), (-1, 1), 7.5), ('FONTSIZE', (0, 2), (-1, 2), 7.5), ('FONTSIZE', (0, 3), (-1, 3), 7.5), ('FONTSIZE', (0, 4), (-1, 4), 7.5), ('FONTSIZE', (0, 5), (-1, 5), 7.5), ('FONTSIZE', (0, 6), (-1, 6), 7.5), ('ALIGN', (0, 0), (-1, 0), 'CENTER'), ('ALIGN', (0, 1), (-1, 1), 'CENTER'), ('ALIGN', (0, 2), (-1, 2), 'CENTER'), ('ALIGN', (0, 3), (-1, 3), 'CENTER'), ('ALIGN', (0, 4), (-1, 4), 'CENTER'), ('ALIGN', (0, 5), (-1, 5), 'CENTER'), ('ALIGN', (0, 6), (-1, 6), 'CENTER'), ] p = canvas.Canvas(response, pagesize=landscape(A4)) listaLaboratorios = [] listaVerificacion = [] duplicado = False numero_periodo = 0 if periodo != "Todos" and docente == "Todos": per = Stage.objects.get(id_sta=periodo) dist = Distributive.objects.filter(sta=per.id_sta) lista = [] for d in dist: sche = Schedule.objects.filter(dist=d.id_dist) if len(sche) > 0: for x in sche: lista.append(x) for ob in lista: if len(listaVerificacion) == 0: listaVerificacion.append(ob.lab) else: for i in listaVerificacion: if i.id_lab == ob.lab.id_lab: duplicado = True break if duplicado == False: listaVerificacion.append(ob.lab) listaLaboratorios.append(ob.lab) duplicado = False for lab in listaLaboratorios: img.drawOn(p, 2.2 * cm, 15.5 * cm) p.setFont('Helvetica', 15) p.drawString(10 * cm, 15 * cm, lab.name_lab) width, height = A4 datos = [[hora, lunes, martes, miercoles, jueves, viernes]] for i in range(0, 6): row = [] row = [ "\n" + arr_i[i] + "\n" + arr_f[i] + "\n", "\n----------\n", "\n----------\n", "\n----------\n", "\n----------\n", "\n----------\n" ] #print row for j in range(1, 6): #print j h_resp = None #for sch in Schedule.objects.all(): for sch in lista: if lab.id_lab == sch.lab_id: (h_i, m_i, s_i) = arr_i[i].split(':') (h_f, m_f, s_f) = arr_f[i].split(':') strin = str(sch.dist) array = strin.split('|') (h_a_i, m_a_i, s_a_i) = str(sch.hour_start).split(':') (h_a_f, m_a_i, s_a_i) = str(sch.hour_end).split(':') if ((sch.day == str(j)) and (h_i >= h_a_i) and (h_f <= h_a_f)): #print str(sch.hour_start) + " "+ str(sch.hour_end) h_resp = "\n" + array[2] + "\n" + array[ 3] + "\n" + array[0] #print array[3]+"\n"+array[2] row[j] = h_resp #print row datos.append(row) tabla = Table(data=datos, style=estilos_tabla, colWidths=[50, 135, 135, 135, 135, 135], rowHeights=[30, 45, 45, 45, 45, 45, 45]) tabla.Align = "CENTER" tabla.wrapOn(p, width, height) tabla.drawOn(p, 2 * cm, 100) p.setFont('Helvetica', 11) p.drawString(8 * cm, 1.3 * cm, "___________________________") #p.drawString(7.5*cm, 1.3*cm, "Ing. Ronald Christopher Elizalde López") p.drawString(9 * cm, 0.8 * cm, "Administrador de TIC") p.drawString(16 * cm, 1.3 * cm, "__________________________") #p.drawString(16.01*cm, 1.3*cm, "Ing. Jimmy Rolando Molina Rios") p.drawString(16.6 * cm, 0.8 * cm, "Coordinador de la Carrera") p.showPage() if periodo != "Todos" and docente != "Todos": per = Stage.objects.get(id_sta=periodo) dist = Distributive.objects.filter(sta=per.id_sta) lista = [] for d in dist: sche = Schedule.objects.filter(dist=d.id_dist, lab=docente) if len(sche) > 0: for x in sche: lista.append(x) for ob in lista: #lab = Lab.objects.get(id_lab=ob.lab.id_lab) if len(listaVerificacion) == 0: listaVerificacion.append(ob.lab) else: for i in listaVerificacion: if i.id_lab == ob.lab.id_lab: duplicado = True break if duplicado == False: listaVerificacion.append(ob.lab) listaLaboratorios.append(ob.lab) duplicado = False for lab in listaLaboratorios: img.drawOn(p, 2.2 * cm, 15.5 * cm) p.setFont('Helvetica', 15) p.drawString(10 * cm, 15 * cm, lab.name_lab) width, height = A4 datos = [[hora, lunes, martes, miercoles, jueves, viernes]] for i in range(0, 6): row = [] row = [ "\n" + arr_i[i] + "\n" + arr_f[i] + "\n", "\n----------\n", "\n----------\n", "\n----------\n", "\n----------\n", "\n----------\n" ] #print row for j in range(1, 6): #print j h_resp = None #for sch in Schedule.objects.all(): for sch in lista: if lab.id_lab == sch.lab_id: (h_i, m_i, s_i) = arr_i[i].split(':') (h_f, m_f, s_f) = arr_f[i].split(':') strin = str(sch.dist) array = strin.split('|') (h_a_i, m_a_i, s_a_i) = str(sch.hour_start).split(':') (h_a_f, m_a_i, s_a_i) = str(sch.hour_end).split(':') if ((sch.day == str(j)) and (h_i >= h_a_i) and (h_f <= h_a_f)): #print str(sch.hour_start) + " "+ str(sch.hour_end) h_resp = "\n" + array[2] + "\n" + array[ 3] + "\n" + array[0] #print array[3]+"\n"+array[2] row[j] = h_resp #print row datos.append(row) tabla = Table(data=datos, style=estilos_tabla, colWidths=[50, 135, 135, 135, 135, 135], rowHeights=[30, 45, 45, 45, 45, 45, 45]) tabla.Align = "CENTER" tabla.wrapOn(p, width, height) tabla.drawOn(p, 2 * cm, 100) p.setFont('Helvetica', 11) p.drawString(8 * cm, 2 * cm, "___________________________") p.drawString(7.5 * cm, 1.3 * cm, "Ing. Ronald Christopher Elizalde López") p.drawString(9 * cm, 0.8 * cm, "Administrador de TIC") p.drawString(16 * cm, 2 * cm, "__________________________") p.drawString(16.01 * cm, 1.3 * cm, "Ing. Jimmy Rolando Molina Rios") p.drawString(16.6 * cm, 0.8 * cm, "Coordinador de la Carrera") p.showPage() if periodo == "Todos" and docente != "Todos": for st in Stage.objects.all(): #per = Stage.objects.get(id_sta=st.id_dist) dist = Distributive.objects.filter(sta=st.id_sta) lista = [] for d in dist: sche = Schedule.objects.filter(dist=d.id_dist, lab=docente) if len(sche) > 0: for x in sche: lista.append(x) for ob in lista: if len(listaVerificacion) == 0: listaVerificacion.append(ob.lab) else: for i in listaVerificacion: if i.id_lab == ob.lab.id_lab: duplicado = True break if duplicado == False: listaVerificacion.append(ob.lab) listaLaboratorios.append(ob.lab) duplicado = False for lab in listaLaboratorios: img.drawOn(p, 2.2 * cm, 15.5 * cm) p.setFont('Helvetica', 15) p.drawString(13 * cm, 15.6 * cm, 'Periodo ' + str(st.name_sta)) p.setFont('Helvetica', 15) p.drawString(10 * cm, 15 * cm, lab.name_lab) width, height = A4 datos = [[hora, lunes, martes, miercoles, jueves, viernes]] for i in range(0, 6): row = [] row = [ "\n" + arr_i[i] + "\n" + arr_f[i] + "\n", "\n----------\n", "\n----------\n", "\n----------\n", "\n----------\n", "\n----------\n" ] #print row for j in range(1, 6): #print j h_resp = None #for sch in Schedule.objects.all(): for sch in lista: if lab.id_lab == sch.lab_id: (h_i, m_i, s_i) = arr_i[i].split(':') (h_f, m_f, s_f) = arr_f[i].split(':') strin = str(sch.dist) array = strin.split('|') (h_a_i, m_a_i, s_a_i) = str(sch.hour_start).split(':') (h_a_f, m_a_i, s_a_i) = str(sch.hour_end).split(':') if ((sch.day == str(j)) and (h_i >= h_a_i) and (h_f <= h_a_f)): #print str(sch.hour_start) + " "+ str(sch.hour_end) h_resp = "\n" + array[2] + "\n" + array[ 3] + "\n" + array[0] #print array[3]+"\n"+array[2] row[j] = h_resp #print row datos.append(row) tabla = Table(data=datos, style=estilos_tabla, colWidths=[50, 135, 135, 135, 135, 135], rowHeights=[30, 45, 45, 45, 45, 45, 45]) tabla.Align = "CENTER" tabla.wrapOn(p, width, height) tabla.drawOn(p, 2 * cm, 100) p.setFont('Helvetica', 11) p.drawString(8 * cm, 2 * cm, "___________________________") p.drawString(7.5 * cm, 1.3 * cm, "Ing. Ronald Christopher Elizalde López") p.drawString(9 * cm, 0.8 * cm, "Administrador de TIC") p.drawString(16 * cm, 2 * cm, "__________________________") p.drawString(16.01 * cm, 1.3 * cm, "Ing. Jimmy Rolando Molina Rios") p.drawString(16.6 * cm, 0.8 * cm, "Coordinador de la Carrera") p.showPage() listaVerificacion = [] listaLaboratorios = [] p.save() return response
def ComputerReport(request): if request.method == 'POST': lab_opc = request.POST['selectLaboratorio']; response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'filename="Reporte_Computadores.pdf"' styles = getSampleStyleSheet() styleN = styles["BodyText"] styleN.alignment = TA_LEFT styleN.fontSize = 6.2 styleBH = styles["Normal"] styleBH.alignment = TA_CENTER styleBH.fontSize = 10 styleBH.color = colors.white img= (Image('static/images/sicolab_carr.png', width=17*cm, height=3.2*cm)) pc= Paragraph("\nCOMPUTADOR\n", styleBH) mac= Paragraph("\nMAC\n", styleBH) ip= Paragraph("\nDDIRECCIÓN IP\n", styleBH) estilos_tabla=[ ('GRID', (0, 1), (-1, -1), 0.5, colors.transparent), ('BOX', (0, 0), (-1, -1), 2, colors.gray), ('BACKGROUND', (0, 0), (12, 0), colors.lightblue), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('FONTSIZE', (0, 0), (-1, 0), 12), ] p = canvas.Canvas(response, pagesize=A4) if lab_opc == "Todos": for lab in Lab.objects.all(): img.drawOn(p , 2*cm, 25*cm) p.setFont('Helvetica', 13) p.drawString(2*cm, 24*cm, lab.name_lab) width, height = A4 height_t=650 datos = [[pc, mac, ip]] for comp in Computer.objects.all(): row= [] if lab.id_lab == comp.lab_id: row=[comp.name_comp, comp.mac_comp, comp.ip_comp] height_t=height_t-16 print row datos.append(row) tabla = Table(data=datos, style= estilos_tabla , colWidths=[135, 135], rowHeights=15) tabla.Align = "CENTER" tabla.wrapOn(p, width, height) tabla.drawOn(p, 3.6*cm, height_t-2) p.setFont('Helvetica', 11) p.drawString(3*cm, 3*cm, "___________________________") p.drawString(4*cm, 2.3*cm, "Administrador de TIC") #p.drawString(2.5*cm, 1.8*cm, "Ing. Ronald Christopher Elizalde López") p.drawString(13*cm, 3*cm, "__________________________") p.drawString(13.6*cm, 2.3*cm, "Coordinador de la carrera") #p.drawString(13.01*cm, 1.8*cm, "Ing. Jimmy Rolando Molina Rios") p.showPage() if lab_opc != "Todos": print "hola prro" for lab in Lab.objects.filter(id_lab=lab_opc): img.drawOn(p , 2*cm, 25*cm) p.setFont('Helvetica', 13) p.drawString(2*cm, 24*cm, lab.name_lab) width, height = A4 height_t=650 datos = [[pc, mac, ip]] for comp in Computer.objects.all(): row= [] if lab.id_lab == comp.lab_id: row=[comp.name_comp, comp.mac_comp, comp.ip_comp] height_t=height_t-16 print row datos.append(row) tabla = Table(data=datos, style= estilos_tabla , colWidths=[135, 135], rowHeights=15) tabla.Align = "CENTER" tabla.wrapOn(p, width, height) tabla.drawOn(p, 3.6*cm, height_t-2) p.setFont('Helvetica', 11) p.drawString(3*cm, 3*cm, "___________________________") p.drawString(4*cm, 2.3*cm, "Administrador de TIC") #p.drawString(2.5*cm, 1.8*cm, "Ing. Ronald Christopher Elizalde López") p.drawString(13*cm, 3*cm, "__________________________") p.drawString(13.6*cm, 2.3*cm, "Coordinador de la carrera") #p.drawString(13.01*cm, 1.8*cm, "Ing. Jimmy Rolando Molina Rios") p.showPage() p.save() return response