def formato_menbrete_pdf(): lista = [] stylemenbrete = ParagraphStyle('Heading1') stylemenbrete.textColor = ('black') stylemenbrete.alignment = TA_CENTER stylemenbrete.fontSize = 12 stylemenbrete.spaceBefore = 5 stylemenbrete.spaceAfter = 5 stylemenbrete.leading = 20 stylemenbrete.bulletIndent = 0 stylemenbrete.allowOrphans = 0 stylemenbrete.bulletFontSize = 10 stylemenbrete.borderWidth = 0 #stylemenbrete.bulletAnchor = start stylemenbrete.borderPadding = 0 stylemenbrete.endDots = None #stylemenbrete.textColor = Color(0,0,0,1) nombre = Paragraph(datos.NOMBRE.upper(), stylemenbrete) #fin ********************************** rif = Paragraph('RIF: %s' % (datos.RIF.upper()), stylemenbrete) direccion = Paragraph('DIRECCION: %s' % (datos.DIRECCION.upper()), stylemenbrete) telefonos = Paragraph('%s / %s' % (datos.TELEFONO, datos.CELULAR), stylemenbrete) codigo_postal = Paragraph('CODIGO POSTAL: %s' % (datos.CODIGO_POSTAL), stylemenbrete) lista.append(nombre) #+rif+direccion+telefonos+codigo_postal) lista.append(rif) #+rif+direccion+telefonos+codigo_postal) lista.append(direccion) lista.append(telefonos) lista.append(codigo_postal)
self._calc() frameT = Frame(self.leftMargin, self.bottomMargin, self.width, self.height, 0, 0, 0, 0, id='normal') self.addPageTemplates([PageTemplate(id='default',frames=frameT, onPage=onFirstPage,pagesize=self.pagesize)]) BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker) font = 'Times-Roman' if len(sys.argv) == 5: pdfmetrics.registerFont(TTFont('font', sys.argv[4])) font = 'font' ParaStyle = ParagraphStyle("default") ParaStyle.fontName = font ParaStyle.fontsize = 10 ParaStyle.leading = 11.16 ParaStyle.alignment = TA_LEFT ParaStyle.allowOrphans = 1 ParaStyle.allowWidows = 1 ParaStyle.spaceBefore = 0 ParaStyle.spaceAfter = 0 ParaStyle.leftIndent = 0 ParaStyle.rightIndent = 0 height = 1000 width = int(sys.argv[2]) Elements = [] def p(txt, style=ParaStyle): Elements.append(Paragraph(txt, style)) text = open(sys.argv[1], 'r').read() # Using the complete string leads to very long runtimes, splitting the string into
def lista_despacho_pdf(request, lista_pk, queryset): response = HttpResponse(content_type='application/pdf') pdf_name = "<b>Factura-Recepcion.pdf</b>" # llamado clientes # la linea 26 es por si deseas descargar el pdf a tu computadora #response['Content-Disposition'] = 'attachment; filename=%s-%s/%s/%s.pdf'%(pdf_name, tiempo.day,tiempo.month, tiempo.year) buff = BytesIO() datos = DATOS_DE_LA_EMPRESA.objects.get(pk=1) doc = SimpleDocTemplate( buff, pagesize=letter, rightMargin=40, leftMargin=40, topMargin=60, bottomMargin=18, ) cambio = False if type(lista_pk) == int: lista_pk = [lista_pk] cambio = True model = queryset.filter(id__in=lista_pk, null=False) lista = [] styles = getSampleStyleSheet() lista.append(logo_pdf()) fecha = Paragraph( '<b><i>Fecha: %s/%s/%s</i><b>' % (tiempo.day, tiempo.month, tiempo.year), styles['Normal']) lista.append(Spacer(0, 40)) lista.append(fecha) lista.append(Spacer(0, 10)) style = ParagraphStyle('Heading1') style.textColor = 'black' style.alignment = TA_CENTER style.fontSize = 18 style.spaceAfter = 15 style.spaceBefore = 30 style.spaceAfter = 5 style.leading = 20 style.bulletIndent = 0 style.allowOrphans = 0 style.bulletFontSize = 10 style.fontName = 'Helvetica' header = Paragraph("Listado de Despachos".upper(), style) lista.append(header) lista.append(Spacer(0, 10)) #************Tabla**************************** style_table = ParagraphStyle('Default') #style_table.textColor= 'black' style_table.alignment = TA_CENTER style_table.fontSize = 10 style_table.spaceAfter = 15 style_table.spaceBefore = 0 style_table.spaceAfter = 0 style_table.leading = 10 # anchor de tabla style_table.bulletIndent = 0 style_table.allowOrphans = 0 style_table.bulletFontSize = 5 style_table.fontName = 'Times-Roman' style_table.bulletAnchor = 'start', cont = 0 array = [] headings = ('CODIGO', 'PRODUCTO', 'CICLO', 'CLIENTE', 'CANTIDAD', 'FECHA', 'TOTAL(Bs).') for p in model: pago = IngresoDespacho.objects.get(despacho=p) total = TotalDespacho.objects.get(ingreso=pago) cont += 1 array.append([ Paragraph(p.codigo_en_sistema(), style_table), Paragraph( '%s (<font size=8>%s-%s</font>)' % (p.producto.nombre.upper(), p.variedad.nombre.upper(), p.tipo.nombre.upper()), style_table), Paragraph(p.ciclo_asociado.codigo_en_sistema(), style_table), Paragraph('%s' % p.cliente.nombre_o_razon_social.upper(), style_table), Paragraph('%s Kg.' % p.cantidad_en_Kg, style_table), Paragraph( '%s/%s/%s' % (p.fecha_agregado.day, p.fecha_agregado.month, p.fecha_agregado.year), style_table), Paragraph('%s' % (total.total_Bs), style_table) ]) t = Table([headings] + array) t.setStyle( TableStyle([ ('GRID', (0, 0), (len(headings), -1), 2, colors.grey), ('LINEBELOW', (1, 0), (-1, 0), 2, colors.grey), ('BACKGROUND', (0, 0), (-1, 0), colors.HexColor(0x41a02a)), ('BACKGROUND', (0, 1), (len(headings), len(array)), colors.HexColor(0xdbf706)), #('BACKGROUND', (0, 0), (-3, 0), colors.yellow), #('BACKGROUND', (0, 0), (-1, 0), colors.palegreen)d1e82af7 ])) lista.append(t) #recepcion= Recepcion.objects.get(pk=pk) doc.build(lista) response.write(buff.getvalue()) buff.close() return response
def factura_despacho_pdf(request, pk): response = HttpResponse(content_type='application/pdf') pdf_name = "Factura-Recepcion.pdf" # llamado clientes # la linea 26 es por si deseas descargar el pdf a tu computadora #response['Content-Disposition'] = 'attachment; filename=%s-%s/%s/%s.pdf'%(pdf_name, tiempo.day,tiempo.month, tiempo.year) buff = BytesIO() datos = DATOS_DE_LA_EMPRESA.objects.get(pk=1, null=False) despacho = Despacho.objects.get(pk=pk) pago = IngresoDespacho.objects.get(despacho=despacho, null=False) total = TotalDespacho.objects.get(ingreso=pago, null=False) doc = SimpleDocTemplate( buff, pagesize=letter, rightMargin=40, leftMargin=40, topMargin=60, bottomMargin=18, ) styles = getSampleStyleSheet() lista = [] stylefac = ParagraphStyle('Heading1') stylefac.textColor = ('red') stylefac.alignment = TA_RIGHT stylefac.fontSize = 20 stylefac.spaceBefore = 5 stylefac.spaceAfter = 5 stylefac.leading = -20 stylefac.bulletIndent = 0 stylefac.allowOrphans = 0 stylefac.bulletFontSize = 10 stylefac.borderWidth = 0 #stylemenbrete.bulletAnchor = start stylefac.borderPadding = 0 stylefac.endDots = None lista.append(Paragraph('%s' % despacho.codigo_en_sistema(), stylefac)) lista.append( Paragraph('<font size=10 color=black><b>NO. Control<b></font>', stylefac)) lista.append(logo_pdf()) lista.append(Spacer(0, 10)) stylemenbrete = ParagraphStyle('Heading1') stylemenbrete.textColor = ('black') stylemenbrete.alignment = TA_CENTER stylemenbrete.fontSize = 8 stylemenbrete.spaceBefore = 5 stylemenbrete.spaceAfter = 5 stylemenbrete.leading = 10 stylemenbrete.bulletIndent = 0 stylemenbrete.allowOrphans = 0 stylemenbrete.bulletFontSize = 10 stylemenbrete.borderWidth = 0 #stylemenbrete.bulletAnchor = start stylemenbrete.borderPadding = 0 stylemenbrete.endDots = None #stylemenbrete.textColor = Color(0,0,0,1) """MEMBRETE""" nombre = Paragraph('<b>%s</b>' % datos.NOMBRE.upper(), stylemenbrete) #fin ********************************** rif = Paragraph('<b> RIF: %s</b>' % (datos.RIF.upper()), stylemenbrete) direccion = Paragraph('<b> %s</b>' % (datos.DIRECCION.upper()), stylemenbrete) telefonos = Paragraph('<b> %s / %s</b>' % (datos.TELEFONO, datos.CELULAR), stylemenbrete) codigo_postal = Paragraph( '<b> CODIGO POSTAL: %s</b>' % (datos.CODIGO_POSTAL), stylemenbrete) lista.append(nombre) #+rif+direccion+telefonos+codigo_postal) lista.append(rif) #+rif+direccion+telefonos+codigo_postal) lista.append(direccion) lista.append(telefonos) lista.append(codigo_postal) lista.append(Spacer(0, 30)) ############################# fecha = Paragraph( '<b>Fecha de Emision: %s<b>' % (despacho.fecha_emision()), styles['Normal']) lista.append(fecha) lista.append(Spacer(0, 10)) lista.append( Paragraph( '<para alignment=left><font><b>CICLO: %s</b></font>' % str(despacho.ciclo_asociado).upper(), styles['Normal'])) lista.append( Paragraph('<font size=10 color=black ><b>-<b></font>' * 156, styles['Normal'])) lista.append( Paragraph('<font color=red><b>DATOS DEL CLIENTE<b><font> ', styles['Normal'])) #datos De Proovedor style_table = ParagraphStyle('Default') #style_table.textColor= 'black' #style_table.alignment= TA_CENTER style_table.fontSize = 10 style_table.spaceAfter = 15 style_table.spaceBefore = 0 style_table.spaceAfter = 0 style_table.leading = 10 # anchor de tabla style_table.bulletIndent = 0 style_table.allowOrphans = 0 style_table.bulletFontSize = 5 style_table.fontName = 'Helvetica' style_table.bulletAnchor = 'start', array1 = [] array1.append([ Paragraph( '<font color=black><b>NOMBRE O RAZON SOCIAL: %s<b> </font>' % despacho.cliente.nombre_o_razon_social.upper(), style_table), Paragraph( '<para alignment=left><font><b>CI/RIF: %s</b></font>' % despacho.cliente.documentoId.upper(), style_table) ]) array2 = [] array2.append([ Paragraph( '<font><b>DOMICILIO: </b></font><font size=8><b>%s<b></font>' % despacho.cliente.domicilio_fiscal.upper(), style_table), Paragraph( '<para alignment=left><font><b>TELE: %s/%s</b></font>' % (despacho.cliente.telefono, despacho.cliente.celular), style_table) ]) array3 = [] array3.append([ Paragraph( '<font><b>CODIGO: %s</b></font>' % despacho.cliente.codigo_en_sistema(), style_table), Paragraph('<font ><b>DIRIGIDO A: %s</b></font>' % despacho.dirigido_a, style_table) ]) t = Table(array1 + array2 + array3) lista.append(t) lista.append( Paragraph('<font size=10 color=black ><b>-<b></font>' * 156, styles['Normal'])) descripcion = [] headingsDes = [] headingsDes.append([ Paragraph('<font color=black><b>RUBRO <b> </font>', style_table), Paragraph('<para alignment=left><font><b>PRESIO </b></font>', style_table), Paragraph('<para alignment=left><font><b>CANTIDAD</b></font>', style_table), Paragraph('<para alignment=left><font><b>TOTAL NETO. </b></font>', style_table), ]) descripcion.append([ Paragraph( '<font color=black><b>%s<b> </font>' % (despacho.producto_total()), style_table), Paragraph( '<para alignment=left><font><b> %s Bs.</b></font>' % intcomma(pago.precio), style_table), Paragraph( '<para alignment=left><font><b> %s Kg.</b></font>' % intcomma(despacho.cantidad_en_Kg), style_table), Paragraph( '<para alignment=left><font><b> %s Bs.</b></font>' % intcomma(total.total_neto), style_table), ]) separator = ('', '', '', '') #headingsDes=('Rubro', 'precio','Cantidad Recibida', 'Total Neto') imptable = [] impuesto1 = [] print total.impuestos() for i, k in total.impuestos().items(): impuesto1.append([ Paragraph('<font color=black><b> <b> </font>', style_table), Paragraph('<para alignment=left><font><b> </b></font>', style_table), Paragraph('<para alignment=left><font><b>%s </b></font>' % i, style_table), Paragraph( '<para alignment=left><font><b>%s Bs.</b></font>' % intcomma(k), style_table), ]) precio_total = [] precio_total.append([ Paragraph('<font color=black><b> <b> </font>', style_table), Paragraph('<para alignment=left><font><b> </b></font>', style_table), Paragraph('<para alignment=left><font><b>TOTAL </b></font>', style_table), Paragraph( '<para alignment=left><font><b>%s Bs. </b></font>' % intcomma(total.total_Bs), style_table), ]) tdescripcion = Table(headingsDes + descripcion + [separator] + impuesto1 + precio_total) lista.append(tdescripcion) lista.append(Spacer(0, 40)) style_analisis = ParagraphStyle('Default') #style_table.textColor= 'black' #style_table.alignment= TA_CENTER style_analisis = ParagraphStyle('Default') #style_table.textColor= 'black' #style_table.alignment= TA_CENTER style_analisis.fontSize = 10 style_analisis.spaceAfter = 15 style_analisis.spaceBefore = 0 style_analisis.spaceAfter = 0 style_analisis.leading = 20 # anchor de tabla style_analisis.bulletIndent = 0 style_analisis.allowOrphans = 0 style_analisis.bulletFontSize = 5 style_analisis.fontName = 'Times-Roman' lista.append( Paragraph( '<para alignment=left><font size=15 color=grey><b> ANALISIS</b></font>', style_analisis)) lista.append( Paragraph( '<para alignment=left><font size=10><b> HUMEDAD:</b> <i>%s%%</i> </font>' % despacho.humedad, style_analisis)) lista.append( Paragraph( '<para alignment=left><font size=10><b>GRANOS DAÑADOS: </b><i>%s%%</i> </font>' % despacho.granos_danados_totales, style_analisis)) lista.append( Paragraph( '<para alignment=left><font size=10><b>GRANOS PARTIDOS:</b> <i>%s%% </i> </font>' % despacho.granos_partidos, style_analisis)) lista.append( Paragraph( '<para alignment=left><font size=10><b>TEMPERATURA PROMEDIO:</b> <i>%s°C</i></font>' % despacho.temperatura_promedio, style_analisis)) lista.append( Paragraph( '<para alignment=left><font size=10><b>OTROS:</b> <i>%s%% </i> </font>' % despacho.otros, style_analisis)) doc.build(lista) response.write(buff.getvalue()) buff.close() return response
def lista_clientes_pdf(request): print "Genero el PDF" response = HttpResponse(content_type='application/pdf') pdf_name = "Listado-de-Proovedores.pdf" # llamado clientes # la linea 26 es por si deseas descargar el pdf a tu computadora #response['Content-Disposition'] = 'attachment; filename=%s-%s/%s/%s.pdf'%(pdf_name, tiempo.day,tiempo.month, tiempo.year) buff = BytesIO() doc = SimpleDocTemplate( buff, pagesize=letter, rightMargin=40, leftMargin=40, topMargin=60, bottomMargin=18, ) styles = getSampleStyleSheet() lista = [] lista.append(logo_pdf()) fecha = Paragraph( '<b><i>Fecha: %s/%s/%s</i></b>' % (tiempo.day, tiempo.month, tiempo.year), styles['Normal']) lista.append(Spacer(0, 40)) lista.append(fecha) lista.append(Spacer(0, 10)) style = ParagraphStyle('Heading1') style.textColor = 'black' style.alignment = TA_CENTER style.fontSize = 18 style.spaceAfter = 15 style.spaceBefore = 30 style.spaceAfter = 5 style.leading = 20 style.bulletIndent = 0 style.allowOrphans = 0 style.bulletFontSize = 10 style.fontName = 'Helvetica' header = Paragraph("<b>Listado de Clientes</b>".upper(), style) lista.append(header) lista.append(Spacer(0, 10)) #************Tabla**************************** style_table = ParagraphStyle('Default') #style_table.textColor= 'black' #style_table.alignment= TA_CENTER style_table.fontSize = 10 style_table.spaceAfter = 15 style_table.spaceBefore = 0 style_table.spaceAfter = 0 style_table.leading = 20 # anchor de tabla style_table.bulletIndent = 0 style_table.allowOrphans = 0 style_table.bulletFontSize = 5 style_table.fontName = 'Times-Roman' style_table.bulletAnchor = 'start', cont = 0 array = [] headings = ('N', 'CODIGO', 'NOMBRE', 'CI/RIF', 'DOMICILIO FISCAL', 'TELEFONO', 'CELULAR') for p in Cliente.objects.filter( habilitado=True).order_by('fecha_agregado'): cont += 1 array.append([ Paragraph(str(cont), style_table), Paragraph(p.codigo_en_sistema(), style_table), Paragraph(p.nombre_o_razon_social.title(), style_table), Paragraph(p.documentoId.title(), style_table), Paragraph(p.domicilio_fiscal.title(), style_table), Paragraph(p.telefono, style_table), Paragraph(p.celular, style_table) ]) t = Table([headings] + array) t.setStyle( TableStyle([ ('GRID', (0, 0), (len(headings), -1), 2, colors.grey), ('LINEBELOW', (1, 0), (-1, 0), 2, colors.grey), ('BACKGROUND', (0, 0), (-1, 0), colors.HexColor(0x41a02a)), ('BACKGROUND', (0, 1), (len(headings), len(array)), colors.HexColor(0xdbf706)), #('BACKGROUND', (0, 0), (-3, 0), colors.yellow), #('BACKGROUND', (0, 0), (-1, 0), colors.palegreen)d1e82af7 ])) lista.append(t) doc.build(lista) response.write(buff.getvalue()) buff.close() return response
def info_productor_pdf(request, pk): response = HttpResponse(content_type='application/pdf') pdf_name = "info-de-Productor.pdf" # llamado clientes # la linea 26 es por si deseas descargar el pdf a tu computadora print inch #response['Content-Disposition'] = 'attachment; filename=%s-%s/%s/%s.pdf'%(pdf_name, tiempo.day,tiempo.month, tiempo.year) #response['Content-Disposition'] = 'filename="archivo.pdf"' buff = BytesIO() doc = SimpleDocTemplate(buff, pagesize=letter, rightMargin=40, leftMargin=40, topMargin=60, bottomMargin=18, showBoundary=0, title='Info-Productores', onPage='doNothing', onPageEnd='doNothing') lista = [] styles = getSampleStyleSheet() #menbrete ************************ lista.append(logo_pdf()) fecha = Paragraph( '<b><i>Fecha: %s/%s/%s</i></b>' % (tiempo.day, tiempo.month, tiempo.year), styles['Normal']) lista.append(Spacer(0, 25)) lista.append(fecha) lista.append(Spacer(0, 20)) style = ParagraphStyle('Heading1') style.textColor = 'black' style.alignment = TA_CENTER style.fontSize = 16 style.spaceAfter = 15 style.spaceBefore = 15 style.spaceAfter = 5 style.leading = 20 style.bulletIndent = 0 style.allowOrphans = 0 style.bulletFontSize = 10 header = Paragraph("<b>Informacion del Proovedor</b>".upper(), style) #******Modelos******** lista.append(header) lista.append(Spacer(0, 25)) p = Productor.objects.get(pk=pk, habilitado=True, null=False) zona = Productor.zona.contar_zonas(pk=pk, null=False) #******Modelos******** # style_C = ParagraphStyle('Normal') style_C.alignment = TA_RIGHT style_C.fontSize = 14 style_C.textColor = 'black' style_N = ParagraphStyle('Normal') style_N.alignment = TA_LEFT style_N.fontSize = 12 style_N.textColor = 'black' style_table = ParagraphStyle('Default') #style_table.textColor= 'black' #style_table.alignment= TA_CENTER style_table.fontSize = 10 style_table.spaceAfter = 15 style_table.spaceBefore = 0 style_table.spaceAfter = 0 style_table.leading = 20 # anchor de tabla style_table.bulletIndent = 0 style_table.allowOrphans = 0 style_table.bulletFontSize = 5 style_table.fontName = 'Times-Roman' style_table.bulletAnchor = 'start', codigo_en_sistema = Paragraph( '<font ><b>CODIGO EN SISTEMA:</b> %s</font>' % p.codigo_en_sistema(), style_C) lista.append(codigo_en_sistema) lista.append(Spacer(0, 5)) lista.append( Paragraph('<b>NUMERO DE ZONAS:</b>%s' % zona['CantZonas'], style_N)) lista.append(Spacer(0, 10)) lista.append( Paragraph( '<b> CANTIDAD DE HECTAREAS:</b> %s Hect.' % zona['CantHectareas'], style_N)) lista.append(Spacer(0, 20)) array_datos = [] lista.append(Paragraph('<font><b>INFORMACION BASICA</b></font>', style_N)) lista.append(Spacer(0, 20)) title_datos = ('Nombre o Razon Social', 'CI/RIF', 'Domicilio Fiscal') array_datos.append([ Paragraph(p.nombre_o_razon_social.title(), style_table), Paragraph(p.documentoId.title(), style_table), Paragraph(p.domicilio_fiscal.title(), style_table) ]) t_datos = Table([title_datos] + array_datos) tupla_tabla = [ ('GRID', (0, 1), (len(title_datos), -1), 1, colors.black), ('GRID', (0, 0), (-1, -1), 1, colors.black), ('LINEBELOW', (1, 0), (-1, 0), 1, colors.black), ('BACKGROUND', (0, 0), (-1, 0), colors.grey), ('BACKGROUND', (0, 1), (len(title_datos), len(array_datos)), colors.white) #HexColor(0x979494)), #('BACKGROUND', (0, 0), (-3, 0), colors.yellow), #('BACKGROUND', (0, 0), (-1, 0), colors.palegreen)d1e82af7 ] t_datos.setStyle(TableStyle(tupla_tabla)) #414141 lista.append(t_datos) array_referencia = [] title_referencia = ('TELEFONO', 'CELULAR', 'E-MAIL') array_referencia.append([ Paragraph(p.telefono, style_table), Paragraph(p.celular, style_table), Paragraph(p.e_mail, style_table) ]) t_referencia = Table([title_referencia] + array_referencia) t_referencia.setStyle(TableStyle(tupla_tabla)) lista.append(t_referencia) array_banco = [] encabesado_banco = ('', 'CUENTA PRINCIPAL', '') title_banco = ('CUENTA', 'BANCO', 'TIPO') array_banco.append([ Paragraph(p.cuenta_bancaria, style_table), Paragraph(p.banco.nombre.title(), style_table), Paragraph(p.tipo_cuenta.nombre.title(), style_table), ]) t_banco = Table([title_banco] + array_banco) t_banco.setStyle(TableStyle(tupla_tabla)) lista.append(t_banco) array_afiliacion = [] title_afiliacion = ('FECHA DE AGREGADO', 'REFENCIA', 'OBSERVACION') array_afiliacion.append([ Paragraph( '%s/%s/%s' % (p.fecha_agregado.day, p.fecha_agregado.month, p.fecha_agregado.year), style_table), Paragraph(p.referencia_folder, style_table), Paragraph(p.observacion, style_table) ]) t_afiliacion = Table([title_afiliacion] + array_afiliacion) t_afiliacion.setStyle(TableStyle(tupla_tabla)) lista.append(t_afiliacion) doc.build( lista ) #, onFirstPage = myFirstPage, onLaterPages = myLaterPages)#doc.build(story, onFirstPage = myFirstPage, onLaterPages = myLaterPages) response.write(buff.getvalue()) buff.close() return response
def rubro_pdf(request): print "Genero el PDF" response = HttpResponse(content_type='application/pdf') pdf_name = "Listado-de-rubros.pdf" # llamado clientes # la linea 26 es por si deseas descargar el pdf a tu computadora #response['Content-Disposition'] = 'attachment; filename=Listado_de_rubros-%s/%s/%s.pdf'%(tiempo.day,tiempo.month, tiempo.year) buff = BytesIO() doc = SimpleDocTemplate( buff, pagesize=letter, rightMargin=40, leftMargin=40, topMargin=60, bottomMargin=18, ) lista = [] styles = getSampleStyleSheet() lista.append(logo_pdf()) #<<<<<<< HEAD style = ParagraphStyle('Heading1') style.textColor = 'black' style.alignment = TA_CENTER style.fontSize = 18 style.spaceAfter = 15 style.spaceBefore = 30 style.spaceAfter = 5 style.leading = 20 style.bulletIndent = 0 style.allowOrphans = 0 style.bulletFontSize = 10 style.fontName = 'Helvetica' fecha = Paragraph( '<font><b><i>Fecha: %s/%s/%s</i><b></font>' % (tiempo.day, tiempo.month, tiempo.year), styles['Normal']) #======= #>>>>>>> c39095c0cdc5175aaf93d43954826f4ba55db4a2 lista.append(Spacer(0, 40)) lista.append(fecha) lista.append(Spacer(0, 10)) style_table = ParagraphStyle('Default') #style_table.textColor= 'black' #style_table.alignment= TA_CENTER style_table.fontSize = 10 style_table.spaceAfter = 15 style_table.spaceBefore = 0 style_table.spaceAfter = 0 style_table.leading = 20 # anchor de tabla style_table.bulletIndent = 0 style_table.allowOrphans = 0 style_table.bulletFontSize = 5 style_table.fontName = 'Times-Roman' header = Paragraph("<b>LISTADO DE RUBROS</b>", style) lista.append(header) lista.append(Spacer(0, 10)) headings = ('Codigo En Sistema', 'Nombre', 'Nombre Cientifico', 'T/Humedad', 'T/Impureza') array = [] for p in Rubro.objects.filter(null=False): array.append([ Paragraph(p.codigo_en_sistema(), style_table), Paragraph(p.nombre, style_table), Paragraph(p.nombre_cientifico, style_table), Paragraph('%s' % p.tolerancia_humedad, style_table), Paragraph('%s' % p.tolerancia_impureza, style_table) ]) t = Table([headings] + array) t.setStyle( TableStyle([ ('GRID', (0, 0), (len(headings), -1), 2, colors.grey), ('LINEBELOW', (1, 0), (-1, 0), 2, colors.grey), ('BACKGROUND', (0, 0), (-1, 0), colors.HexColor(0x41a02a)), ('BACKGROUND', (0, 1), (len(headings), len(array)), colors.HexColor(0xdbf706)), #('BACKGROUND', (0, 0), (-3, 0), colors.yellow), #('BACKGROUND', (0, 0), (-1, 0), colors.palegreen)d1e82af7 ])) lista.append(t) doc.build(lista) response.write(buff.getvalue()) buff.close() return response
def info_zona_productor_pdf(request, pk): response = HttpResponse(content_type='application/pdf') pdf_name = "info-de-Productor.pdf" # llamado clientes # la linea 26 es por si deseas descargar el pdf a tu computadora #response['Content-Disposition'] = 'attachment; filename=%s-%s/%s/%s.pdf'%(pdf_name, tiempo.day,tiempo.month, tiempo.year) #response['Content-Disposition'] = 'filename="archivo.pdf"' buff = BytesIO() doc = SimpleDocTemplate(buff, pagesize=letter, rightMargin=40, leftMargin=40, topMargin=60, bottomMargin=18, ) styles = getSampleStyleSheet() p= Productor.objects.get(pk=pk, habilitado=True) zonas = Productor.zona.contar_zonas(pk=pk) style_C= ParagraphStyle('Normal') style_C.alignment= TA_RIGHT style_C.fontSize= 14 style_C.textColor= 'black' lista=[] lista.append(logo_pdf()) fecha= Paragraph('<b><i>Fecha: %s/%s/%s</i></b>'%(tiempo.day,tiempo.month, tiempo.year), styles['Normal']) lista.append(Spacer(0,25)) lista.append(fecha) lista.append(Spacer(0,30)) lista.append(Paragraph("<font><b>CODIGO:</b></font> %s"%p.codigo_en_sistema().upper(), style_C)) lista.append(Spacer(0,10)) lista.append(Paragraph("<font ><b>PROOVEDOR:</b></font> %s"%p.codigo_en_sistema().upper(), style_C)) lista.append(Spacer(0,10)) lista.append(Paragraph("<font ><b>ASIGNADO:</b></font> %s"%p.nombre_o_razon_social.upper(), style_C)) lista.append(Spacer(0,10)) lista.append(Paragraph("<font><b>TOTAL DE ZONAS:</b></font> %s"%zonas['CantZonas'], style_C)) lista.append(Spacer(0,10)) lista.append(Paragraph("<font><b>HECTAREAS:</b></font> %s Hect."%zonas['CantHectareas'], style_C)) #***************************** lista.append(Spacer(0,20)) style= ParagraphStyle('Heading1') style.textColor= 'black' style.alignment= TA_CENTER style.fontSize= 18 style.spaceAfter=15 style.spaceBefore= 50 style.spaceAfter=5 style.leading = 20 style.bulletIndent = 0 style.allowOrphans = 0 style.bulletFontSize = 10 style.fontName='Helvetica' lista.append(Paragraph("<b>ZONAS ASIGANADAS</b>".upper(), style)) lista.append(Spacer(0,10)) #**************************** style_table= ParagraphStyle('Default') #style_table.textColor= 'black' style_table.alignment= TA_CENTER style_table.fontSize= 10 style_table.spaceAfter=15 style_table.spaceBefore= 0 style_table.spaceAfter=0 style_table.leading = 20 # anchor de tabla style_table.bulletIndent = 0 style_table.allowOrphans = 0 style_table.bulletFontSize = 5 style_table.fontName='Times-Roman' style_table.bulletAnchor= 'start', cont= 0 array=[] headings = ['N','NOMBRE', 'ESTADO', 'MUNICIPIO', 'EXTENCION'] for zona in zonas['zonas']: cont+=1 array.append([Paragraph(str(cont), style_table), Paragraph(zona.zona, style_table), Paragraph(zona.estado, style_table), Paragraph(zona.municipio, style_table), Paragraph('%s Hect.'%zona.hectareas, style_table)]) t = Table([headings] + array) t.setStyle(TableStyle( [ ('GRID', (0, 0), (len(headings), -1), 2, colors.grey), ('LINEBELOW', (1, 0), (-1, 0), 2, colors.grey), ('BACKGROUND', (0, 0), (-1, 0), colors.HexColor(0x41a02a)), ('BACKGROUND', (0, 1), (len(headings), len(array)), colors.HexColor(0xdbf706)), #('BACKGROUND', (0, 0), (-3, 0), colors.yellow), #('BACKGROUND', (0, 0), (-1, 0), colors.palegreen)d1e82af7 ] )) lista.append(t) doc.build(lista) response.write(buff.getvalue()) buff.close() return response