def header_footer(self, canvas, doc): canvas.saveState() height_adjust = self.add_banner(canvas, doc) # Document Header if self.pdf_components.get('hdr_image', None) and self.firstPage: header = Image(self.pdf_components.get('hdr_image'), height=25 * mm, width=191 * mm) header.drawOn(canvas, doc.rightMargin, doc.height + doc.topMargin - 15 * mm) self.firstPage = False elif self.firstPage: header = Paragraph(self.pdf_components.get('hdr_html', ''), self.style['centered']) w, h = header.wrap(doc.width, doc.topMargin) header.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin - height_adjust * h) # Document Footer if self.pdf_components.get('ftr_image', None): footer = Image(self.pdf_components.get('ftr_image'), 8.5 * inch, 1.8 * inch) footer.drawOn(canvas, 0, 0) else: footer = Paragraph(self.pdf_components.get('ftr_html', ''), self.style['centered']) w, h = footer.wrap(doc.width, doc.bottomMargin) footer.drawOn(canvas, doc.leftMargin, height_adjust * h) # Release the Canvas canvas.restoreState()
def get_letterhead_page(canvas, doc): # Save the state of our canvas so we can draw on it canvas.saveState() styles = getSampleStyleSheet() base_path = join(settings.BASE_DIR, 'static/assets/report/') escudo = Image(base_path + 'escudo_morona.png', width=6*cm,height=2*cm) logo = Image(base_path + 'logo_morona.jpg', width=2*cm,height=2*cm) aside = Image(base_path + 'aside.png', width=1*cm,height=10*cm) footer_caption = Image(base_path + 'footer-caption.png', width=6.5*cm,height=1.5*cm) footer_image = Image(base_path + 'footer-image.png', width=3*cm,height=1.5*cm) w, h = escudo.wrap(doc.width, doc.topMargin) escudo.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin - 20) w, h = logo.wrap(doc.width, doc.topMargin) logo.drawOn(canvas, doc.leftMargin + 480, doc.height + doc.topMargin - 20) w, h = aside.wrap(doc.width, doc.topMargin) aside.drawOn(canvas, doc.leftMargin + 510, doc.height + doc.topMargin - 375) w, h = footer_caption.wrap(doc.width, doc.topMargin) footer_caption.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin - 770) w, h = footer_image.wrap(doc.width, doc.topMargin) footer_image.drawOn(canvas, doc.leftMargin + 430, doc.height + doc.topMargin - 770) # Release the canvas canvas.restoreState()
def headerFooter(canvas, doc): canvas.saveState() header = Image(f'./skmk/header.png', 19 * cm, 2.5 * cm) w, h = header.wrap(doc.width, 2.5 * cm) header.drawOn(canvas, 1 * cm, doc.height + 4 * cm) footer = Image(f'./skmk/footer.png', 19 * cm, 1.8 * cm) w, h = footer.wrap(doc.width, 2.5 * cm) footer.drawOn(canvas, 1 * cm, h - 1.5 * cm) canvas.restoreState()
def _header_footer(canvas, doc): # Save the state of our canvas so we can draw on it canvas.saveState() styles = getSampleStyleSheet() # Header img = utils.ImageReader('https://www.martinhelder.pt/img/logotipo.png') img_w, img_h = img.getSize() header = Image('https://www.martinhelder.pt/img/logotipo.png', width=0.7 * img_w, height=0.7 * img_h) width, height = header.wrap(doc.width, doc.topMargin) header.drawOn(canvas, doc.leftMargin + 0 * width, doc.height + doc.topMargin - height + 35) # Footer right = ParagraphStyle('BodyText', alignment=TA_RIGHT, fontName='Vera') footer = Table([[ Paragraph(str(doc.page), styles['BodyText']), Paragraph( "Documento gerado a " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), right) ]], colWidths=(None, 0.8 * doc.width)) footer.wrap(doc.width, doc.topMargin) footer.drawOn(canvas, doc.leftMargin, 0.6 * doc.bottomMargin) # Release the canvas canvas.restoreState()
def wrap(self, awidth, aheight): wr, wh = self.maxw / awidth, self.maxh / aheight if wr > 1 or wh > 1: r = max(wr, wh) self.drawHeight = self.maxh / r self.drawWidth = self.maxw / r return Image.wrap(self, awidth, aheight)
def addHbcHeader(self): c = self.c top = self.top S = ParagraphStyle('dflt-right') S.alignment = 2 img = utils.ImageReader('logoHD.png') iw, ih = img.getSize() aspect = ih / float(iw) width = 200 I = Image('logoHD.png', width=width, height=(width * aspect)) w, h = I.wrap(200, 50) I.drawOn(self.c, 14 * cm, top - h - 1 * cm) P = Paragraph( "<strong>HEADBANG CLUB</strong><br/>" + "15 RUE FERDINAND BUISSON<br/>" + "16160 GOND-PONTOURE<br/>CHARENTE - FRANCE<br/>" + "VAT - FR63824464127<br/>" + "TEL - +33 (0)6 63 92 55 96<br/>" + "[email protected] / [email protected]", S) w, h = P.wrap(300, 50) P.drawOn(self.c, 21 * cm - w - 0.5 * cm, self.top - h - 4 * cm) pass
def wrap(self, awidth, aheight): wr, wh = self.maxw / awidth, self.maxh / aheight if wr > 1 or wh > 1: r = max(wr, wh) self.drawHeight = self.maxh / r self.drawWidth = self.maxw / r return Image.wrap(self, awidth, aheight)
def _header_footer(canvas,doc): #guardamos el estado de nuestro canvas , para poder dibujar en el canvas.saveState() canvas.setTitle("Cotizacion Cliente") styles = getSampleStyleSheet() #header header = Image('/home/borbolla/metrology/static_media/assets/images/borbolla_metrology_logo.jpg' ) header.drawHeight = 60 header.drawWidth = 424 header.hAlign = 'RIGHT' w , h = header.wrap(doc.width , doc.topMargin) header.drawOn(canvas , doc.leftMargin , 700) marcas = Image('/home/borbolla/metrology/static_media/assets/images/marcas.png' ) marcas.drawWidth = 90 marcas.drawHeight = 477 marcas.drawOn(canvas , 20,200) marcas2 = Image('/home/borbolla/metrology/static_media/assets/images/logo.png' ) marcas2.drawWidth = 116 marcas2.drawHeight = 34 marcas2.drawOn(canvas , 20,150) # Footer footer = Paragraph('www.borbollametrology.com', styles['Normal']) w, h = footer.wrap(doc.width, doc.bottomMargin) footer.drawOn(canvas, doc.leftMargin, h) # Release the canvas canvas.restoreState()
def draw(self): canvas = self.canv h, w = float(self.img.height), float(self.img.width) if not self.img.iptc.caption: fsz = 5.0 else: fsz = 0.85*inch if w > h*1.3: fsz = 0.25*inch s = self.size - fsz if h > w: ratio = w / h h = s w = s * ratio else: ratio = h / w w = s h = s * ratio img = Image(self.img.path, height=h, width=w) w, h = img.wrap(w, h) iw, ih = w, h imgx, imgy = (self.size - s - (fsz/2.0), self.size - h) img.drawOn(self.canv, imgx, imgy) print "%.2f x %.2f (%.2f x %.2f dpi)" % (w/inch, h/inch, float(o.width) / (w/inch), float(o.height) / (h/inch) ) p = Paragraph(self.img.iptc.caption, styleN) w, h = p.wrap(self.size - 10.0, 1.3*inch) print "Text %.2f x %.2f" % (w/inch, h/inch) p.drawOn(self.canv, 3.0, (imgy - h) - 3.0) canvas.rect(imgx, imgy, iw, ih, stroke=1, fill=0)
def header_footer(canvas, doc): canvas.saveState() footer = Image('./skpi/footer.png', 19 * cm, 2.5 * cm) w, h = footer.wrap(doc.width, doc.bottomMargin) footer.drawOn(canvas, doc.leftMargin, h) canvas.restoreState()
def wrap(self, availWidth, availHeight): w, h = Image.wrap(self, availWidth, availHeight) if self.maxwidth: if w * self.scale > self.maxwidth: self.scale *= self.maxwidth / (w * self.scale) w *= self.scale h *= self.scale # print('... ', w, h) return w, h
def wrap(self, availWidth, availHeight): w, h = Image.wrap(self, availWidth, availHeight) if self.maxwidth: if w * self.scale > self.maxwidth: self.scale *= self.maxwidth / (w * self.scale) w *= self.scale h *= self.scale # print('... ', w, h) return w, h
def get_letterhead_page(canvas, doc): # Save the state of our canvas so we can draw on it canvas.saveState() styles = getSampleStyleSheet() base_path = join(settings.BASE_DIR, 'static/assets/img/') logo = Image(base_path + 'logo.jpg', width=5 * cm, height=2.5 * cm) w, h = logo.wrap(doc.width, doc.topMargin) logo.drawOn(canvas, doc.leftMargin + 400, doc.height + doc.topMargin - 30) # Release the canvas canvas.restoreState()
def _encabezado(canvas, archivoPDF): """Guarde el estado de nuestro lienzo para que podamos aprovecharlo""" canvas.saveState() estilos = getSampleStyleSheet() # encabezado imagen encabezado_imagen = Image("LOGOCONDORCUNCA-min.png", 150, 169.63) anchura, altura = encabezado_imagen.wrap(archivoPDF.width, archivoPDF.topMargin) encabezado_imagen.drawOn(canvas, 200, 600) # Suelta el lienzo canvas.restoreState()
def _header_footer(canvas, doc): # Save the state of our canvas so we can draw on it canvas.saveState() styles = getSampleStyleSheet() # Header logo = "influxdb/pdf-utils/Logo-Crop-Sensing.png" header = Image(logo, 1.5 * inch, 0.5 * inch) header.hAlign = 'LEFT' #header = Paragraph('This is a multi-line header. It goes on every page. ' * 5, styles['Normal']) w, h = header.wrap(doc.width, doc.topMargin) header.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin - h) # Footer logo2 = "influxdb/pdf-utils/Logo-CIDIS.png" footer = Image(logo2, 2 * inch, 0.5 * inch) footer.hAlign = 'RIGHT' #footer = Paragraph('This is a multi-line footer. It goes on every page. ' * 5, styles['Normal']) w, h = footer.wrap(doc.width, doc.bottomMargin) footer.drawOn(canvas, doc.width - w / 12, h) # Release the canvas canvas.restoreState()
def capa(canvas, doc): cabecalho = Image('static/topFrame.png', 535, 63) w, h = cabecalho.wrap(doc.width, doc.topMargin) cabecalho.drawOn(canvas, doc.leftMargin + 5, doc.height + doc.topMargin - 40) canvas.setFont('Helvetica', 14) canvas.setFillColor(HexColor('#3366cc')) canvas.drawRightString(560, 220, doc_config['laudo']) canvas.setFont('Helvetica', 10) canvas.setFillColor(HexColor('#6a6a6a')) canvas.drawRightString(560, 180, doc_config['nome']) canvas.setFillColor(HexColor('#6a6a6a')) canvas.drawRightString(560, 160, doc_config['empresa']) canvas.setFillColor(HexColor('#6a6a6a')) canvas.drawRightString(560, 140, doc_config['cargo'])
def capa(canvas, doc): cabecalho = Image('static/topFrame.png', 535, 63) w, h = cabecalho.wrap(doc.width, doc.topMargin) cabecalho.drawOn(canvas, doc.leftMargin + 5, doc.height + doc.topMargin - 40) canvas.setFont('Helvetica', 14) canvas.setFillColor(HexColor('#3366cc')) canvas.drawRightString(560, 220, doc_config['laudo']) canvas.setFont('Helvetica', 10) canvas.setFillColor(HexColor('#6a6a6a')) canvas.drawRightString(560, 180, doc_config['nome']) canvas.setFillColor(HexColor('#6a6a6a')) canvas.drawRightString(560, 160, doc_config['empresa']) canvas.setFillColor(HexColor('#6a6a6a')) canvas.drawRightString(560, 140, doc_config['cargo'])
def _header(canvas, doc): # Save the state of our canvas so we can draw on it canvas.saveState() # Header header_url = 'Accountability+Counsel_Logo_Color+(2).png' header = Image('{0}{1}'.format(file_url, header_url), width=112.3, height=29) header.hAlign = 'RIGHT' w, h = header.wrap(doc.width, doc.topMargin) header.drawOn(canvas, w + 530, doc.height + doc.topMargin - h) # Release the canvas canvas.restoreState()
def _header_footer(canvas, doc): # Save the state of our canvas so we can draw on it canvas.saveState() # Header png_path=os.path.dirname(__file__)+os.path.sep+'static'+os.path.sep+'images'+os.path.sep+'nutanixlogo.png' loggerObj.LogMessage("info",file_name + " :: PNG File path - " + png_path) header = Image(png_path, height=0.50 * inch, width=5 * cm) w, h = header.wrap(doc.width, doc.topMargin) header.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin - h) # Footer footer = Paragraph('Tel: 1 (855) 688-2649 | Fax: 1 (408) 916-4039 | Email: [email protected]. © 2014 Nutanix, Inc. All Rights Reserved.', FooterMsgStyle) w, h = footer.wrap(doc.width, doc.bottomMargin) footer.drawOn(canvas, doc.leftMargin, h) # Release the canvas canvas.restoreState()
def _header_factura(canvas,doc): #guardamos el estado de nuestro canvas , para poder dibujar en el canvas.saveState() canvas.setTitle("Factura") styles = getSampleStyleSheet() #header header = Image('/home/borbolla/metrology/static_media/assets/images/logo_servicio.png' ) header.drawHeight = 70 header.drawWidth = 399 header.hAlign = 'RIGHT' w , h = header.wrap(doc.width , doc.topMargin) header.drawOn(canvas , doc.leftMargin , 700) # Footer footer = Paragraph('www.borbollametrology.com', styles['Normal']) w, h = footer.wrap(doc.width, doc.bottomMargin) footer.drawOn(canvas, doc.leftMargin, h) # Release the canvas canvas.restoreState()
def wrap(self,availWidth,availHeight): h, w = Image.wrap(self,availHeight,availWidth) return w, h
def wrap(self, availWidth, availHeight): height, width = Image.wrap(self, availHeight, availWidth) return width, height
def wrap(self, availWidth, availHeight): h, w = Image.wrap(self, availHeight, availWidth) return w, h
def cabecalho(canvas, doc): cabecalho = Image('static/topFrame.png', 535, 63) w, h = cabecalho.wrap(doc.width, doc.topMargin) cabecalho.drawOn(canvas, doc.leftMargin + 5, doc.height + doc.topMargin - 40)
def cabecalho(canvas, doc): cabecalho = Image('static/topFrame.png', 535, 63) w, h = cabecalho.wrap(doc.width, doc.topMargin) cabecalho.drawOn(canvas, doc.leftMargin + 5, doc.height + doc.topMargin - 40)