def header(self, canvas, doc): # Header data = self.page_header_data header_list_left = ["essenza lubricants", "b>" + data['title'].upper(), "b>" + data['depot'].upper()] header_list_right = ["LUBRICANTS", "b>" + "MADE IN " + data['made_in'].upper(), "VALIDITY " + data['valid_from'].upper()] canvas.saveState() x = 12 * mm y = 200 * mm for t in header_list_left: if 'b>' in t: font = "Helvetica-Bold" t = t.split('>')[1] else: font = "Helvetica" textobject = canvas.beginText() textobject.setFont(font, 10) textobject.setTextOrigin( x, y ) textobject.textLine(t) canvas.drawText(textobject) y -= 15 y = 200 * mm canvas.drawImage("logo.jpg", x=(A4[1] / 2) - 15 * mm, y=A4[0] - 23 * mm, width=15 * mm, height=15 * mm) for t in header_list_right: if 'b>' in t: font = "Helvetica-Bold" t = t.split('>')[1] else: font = "Helvetica" textobject = canvas.beginText() textobject.setFont(font, 10) textobject.setTextOrigin( A4[1] - 12 * mm - stringWidth(t, font, 10), y ) textobject.textLine(t) canvas.drawText(textobject) y -= 15 canvas.restoreState()
def myFirstPage(canvas, doc): PAGE_HEIGHT,PAGE_WIDTH = letter canvas.saveState() canvas.drawImage(fondo, 0,0, PAGE_HEIGHT, PAGE_WIDTH ) canvas.setStrokeColorRGB(1,0,1,alpha=0.1) #canvas.setPageSize(landscape(letter)) canvas.setFont('Arial', 8) canvas.drawString(132,670, cuenta_cobro.periodo) canvas.drawString(475, 670, cuenta_cobro.num_cuota) canvas.drawString(132, 653, cuenta_cobro.fecha_transaccion) canvas.drawString(132, 633, cuenta_cobro.no_contrato) seguridad_social = "Adjunto planilla de pago de Seguridad social No %s " % (cuenta_cobro.num_planilla_ss,) seguridad_social = seguridad_social + " correspondiente a los aportes del mes de %s, en los terminos legales." % (cuenta_cobro.mes_planilla_ss) #canvas.drawString(132, 300,textwrap.fill(seguridad_social, 90) ) cuenta_cobro.informe_actividades_periodo = textwrap.fill(cuenta_cobro.informe_actividades_periodo, 105) textobject = canvas.beginText() textobject.setTextOrigin(132, 609) textobject.textLines(cuenta_cobro.informe_actividades_periodo) canvas.drawText(textobject) textobject = canvas.beginText() textobject.setTextOrigin(132, 240) textobject.textLines(textwrap.fill(seguridad_social, 105)) canvas.drawText(textobject) #canvas.drawString(132, 292, "correspondiente a los aportes del mes de %s, en los terminos legales." % (cuenta_cobro.mes_planilla_ss)) canvas.drawCentredString(170, 90, cuenta_cobro.nombre_interventor) canvas.drawCentredString(170, 81, "INTERVENTOR/SUPERVISOR %s" % (cuenta_cobro.cargo_interventor,)) canvas.drawCentredString(415, 90, cuenta_cobro.nombre_beneficiario) canvas.drawCentredString(415, 81, "C.C. No. %s de %s" % (cuenta_cobro.documento_beneficiario, cuenta_cobro.lugar_exp_doc_beneficiario)) SHOW_GRID = False if SHOW_GRID: n = 5 s = 200 #canvas.setStrokeGray(0.90) #canvas.setFillGray(0.90) canvas.setStrokeColorRGB(0,1,1,alpha=0.1) canvas.setFillColorRGB(1,0,1) canvas.setFont('Arial',1) for x in range(s): for y in range(s): canvas.rect(x*n,y*n, width=n, height=n, stroke=1) canvas.drawString(x*n,y*n,"%s,%s" % ((x*n),(y*n)) ) canvas.restoreState()
def main(): # PDF document layout canvas = canvas.Canvas( "H:\College Fourth Year\Development Project\Final Year Project 2018\Forensic Reports\SMS Report.pdf", pagesize=letter) canvas.setLineWidth(.3) canvas.setFont('Helvetica', 12) canvas.drawString(30, 750, 'LYIT MOBILE FORENSICS DIVISION') canvas.drawString( 500, 750, "Date: " + now.strftime("%d-%m-%y")) # Prints date of the report(on the fly) canvas.line(500, 747, 595, 747) canvas.drawString(500, 725, 'Case Number:') canvas.drawString(580, 725, "10") canvas.line(500, 723, 595, 723) # Introduction text line1 = 'This forensic report on sms data has been compiled by the forensic' line2 = 'examiner in conclusion to the investigation into the RTA' line3 = 'case which occurred on the 23/01/2018.' textObject = canvas.beginText(30, 700) lines = [line1, line2, line3] for line in lines: textObject.textLine(line) canvas.drawText(textObject) canvas.save()
def _add_text(self, text, canvas, coords): textobject = canvas.beginText(*coords) textobject.setFont("Helvetica", 14) text = text.replace('\r', '\n').replace('\n\n', '\n') for line in text.split('\n'): textobject.textLine(line.strip()) canvas.drawText(textobject)
def print_line(canvas, y, fontsize, line, force=False): """Prints one line of text on the left-hand side of the label. :param canvas: ReportLab canvas object :param y: vertical coordinate of the lower left corner of the printed text. Note that the origin of the coordinate system is the lower left of the paper. :param fontsize: font size of the text :param line: the text to be printed; it must not contain line breaks :param force: whether `ExcessException` should be raised if the text has to be compressed too much; if ``True``, the text may be compressed as much as necessary :type canvas: canvas.Canvas :type y: float :type fontsize: float :type line: unicode :type force: bool :raises ExcessException: if the line is too long and `force` is ``False`` """ textobject = canvas.beginText() textobject.setFont(institute.reportlab_config.default_fontname, fontsize) width = canvas.stringWidth(line, institute.reportlab_config.default_fontname, fontsize) excess = width / max_width_text if excess > 2 and not force: raise ExcessException elif excess > 1: textobject.setHorizScale(100 / excess) textobject.setTextOrigin(horizontal_margin, y + vertical_margin + vertical_relative_offset * fontsize) textobject.textOut(line) canvas.drawText(textobject)
def __init__(self, canvas, x, y, width, height=0, font=FONT, fontsize=FONTSIZE, align=ALIGN, lineheight=LINEHEIGHT, move_cursor=False): # Make sure these values aren't strings fontsize = float(fontsize) lineheight = float(lineheight) self.canvas = canvas self.font = font self.fontsize = fontsize self.align = align self.x = x self.y = y self.width = width self.move_cursor = move_cursor # Lineheight self.lineheight = fontsize * lineheight # If height was specified. Start 1 line below. self.first_line = y if height: self.first_line += height - self.lineheight self.text = canvas.beginText() # Set font self.text.setFont(self.font, self.fontsize) self.text.setTextOrigin(x, self.first_line) self.space_width = canvas.stringWidth(' ', font, fontsize)
def handle(self, *args, **options): for person in Person.objects.all(): packet = io.BytesIO() can = canvas.Canvas(packet, pagesize=A4) name = "{} {}".format(str(person.first_name), str(person.last_name)) text_width = stringWidth(name) y = 1050 pdf_text_object = canvas.beginText((PAGE_WIDTH - text_width) / 2.0, y) pdf_text_object.textOut(name) can.drawString(10, 100, name) can.save() packet.seek(0) new_pdf = PdfFileReader(packet) existing_pdf = PdfFileReader( open(os.path.join(settings.MEDIA_ROOT, "certificate.pdf"), "rb")) output = PdfFileWriter() page = existing_pdf.getPage(0) page.mergePage(new_pdf.getPage(0)) output.addPage(page) outputStream = open( os.path.join(settings.MEDIA_ROOT, "diplomas", str(person.id) + "-" + "diploma.pdf"), "wb") output.write(outputStream) outputStream.close()
def __init__(self, canvas, x, y, width, height, font='Helvetica', fontsize=11, align='left', lineheight=1, move_cursor=False): # Make sure these values aren't strings fontsize = float(fontsize) lineheight = float(lineheight) self.canvas = canvas self.font = font self.fontsize = fontsize self.align = align self.x = x self.y = y self.height = height self.width = width self.move_cursor = move_cursor # Regular lineheight self.lineheight = fontsize / 72.0 * units.inch self.first_line = y + height - self.lineheight # Adjusted lineheight self.lineheight *= lineheight self.text = canvas.beginText() self.text.setTextOrigin(x, self.first_line) self.space_width = canvas.stringWidth(' ', font, fontsize)
def draw_address(canvas): """ Draws the business address """ canvas.setFont('Helvetica', 9) textobject = canvas.beginText(13 * cm, -2.5 * cm) for line in business_details: textobject.textLine(line) canvas.drawText(textobject)
def draw_due_date(self, canvas, due_date): """Draw due date. This will probably be ignored by quite a few but...""" textobject = canvas.beginText() textobject.setTextOrigin(170*mm, 95*mm) textobject.setFont(self.FONT, 10) textobject.textLine(due_date) canvas.drawText(textobject)
def draw_account_no(self, canvas, account): """Draw the account no""" textobject = canvas.beginText() textobject.setTextOrigin(133*mm, 2.13*cm) textobject.setFont(self.BOLDFONT, 10) textobject.textLine(account) canvas.drawText(textobject)
def draw_payment_info(self, canvas, info): """Add payment information. This will probably be copied and pasted by the member""" textobject = canvas.beginText() textobject.setTextOrigin(1.5*cm, 9.0*cm) textobject.setFont(self.BOLDFONT, 10) textobject.textLine(info) canvas.drawText(textobject)
def draw_address_heading(self, canvas, address): """Draw member's address at the top of the page.""" textobject = canvas.beginText() textobject.setTextOrigin(2.0*cm, 24.5*cm) textobject.setFont(self.FONT, 12) for line in address.split('\n'): textobject.textLine(line) canvas.drawText(textobject)
def drawPageNumbers(canvas, style, pages, availWidth, availHeight, dot=' . '): ''' Draws pagestr on the canvas using the given style. If dot is None, pagestr is drawn at the current position in the canvas. If dot is a string, pagestr is drawn right-aligned. If the string is not empty, the gap is filled with it. ''' pages.sort() pagestr = ', '.join([str(p) for p, _ in pages]) x, y = canvas._curr_tx_info['cur_x'], canvas._curr_tx_info['cur_y'] fontSize = style.fontSize pagestrw = stringWidth(pagestr, style.fontName, fontSize) #if it's too long to fit, we need to shrink to fit in 10% increments. #it would be very hard to output multiline entries. #however, we impose a minimum size of 1 point as we don't want an #infinite loop. Ultimately we should allow a TOC entry to spill #over onto a second line if needed. freeWidth = availWidth - x while pagestrw > freeWidth and fontSize >= 1.0: fontSize = 0.9 * fontSize pagestrw = stringWidth(pagestr, style.fontName, fontSize) if isinstance(dot, strTypes): if dot: dotw = stringWidth(dot, style.fontName, fontSize) dotsn = int((availWidth - x - pagestrw) / dotw) else: dotsn = dotw = 0 text = '%s%s' % (dotsn * dot, pagestr) newx = availWidth - dotsn * dotw - pagestrw pagex = availWidth - pagestrw elif dot is None: text = ', ' + pagestr newx = x pagex = newx else: raise TypeError( 'Argument dot should either be None or an instance of basestring.') tx = canvas.beginText(newx, y) tx.setFont(style.fontName, fontSize) tx.setFillColor(style.textColor) tx.textLine(text) canvas.drawText(tx) commaw = stringWidth(', ', style.fontName, fontSize) for p, key in pages: if not key: continue w = stringWidth(str(p), style.fontName, fontSize) canvas.linkRect('', key, (pagex, y, pagex + w, y + style.leading), relative=1) pagex += w + commaw
def draw_payers_address(self, canvas, address): """Draw member's address at the bottom""" textobject = canvas.beginText() textobject.setTextOrigin(1.5*cm, 5.8*cm) textobject.setFont(self.FONT, 10) address = address.replace('\r','') for line in address.split('\n'): textobject.textLine(line) canvas.drawText(textobject)
def draw_amount(self, canvas, amount): """Draw the amount to be paid""" textobject = canvas.beginText() textobject.setTextOrigin(92*mm, 2.13*cm) textobject.setFont(self.BOLDFONT, 10) textobject.textLine(amount) textobject.setTextOrigin(107*mm, 2.13*cm) textobject.textLine('00') canvas.drawText(textobject)
def draw_recipient_address(self, canvas, address): """Draw the club's address""" textobject = canvas.beginText() textobject.setTextOrigin(11.5*cm, 5.8*cm) textobject.setFont(self.FONT, 10) address=address.replace('\r', '') for line in address.split('\n'): textobject.textLine(line) canvas.drawText(textobject)
def lfleft(canvas): textobject = canvas.beginText() textobject.setTextOrigin(51.2,749) textobject.setFont('Gridnik',27) textobject.textLines(''' LEFT FIELD LABS ''') canvas.drawText(textobject)
def contactleftLaterPages(canvas): textobject = canvas.beginText() textobject.setTextOrigin(51.2,57) textobject.setFont('Akkurat-Light',9) textobject.textLines(''' 510 Victoria Ave Venice CA 90291 www.leftfieldlabs.com ''') canvas.drawText(textobject)
def fillMonthNames(self, canvas): for x in range(0, 12): textobject = canvas.beginText() textobject.setTextOrigin( self.monthPositions[x][0], 7 * self.individualDateTextBoxSize[0] + A4[1] - self.monthPositions[x][1]) textobject.setFont("Helvetica", 14) textobject.textOut(calendar.month_name[x + 1]) canvas.drawText(textobject)
def _footer(canvas, doc): splunkLayoutSettings = PAPERSIZES[doc.splunkPaperSize] canvas.saveState() canvas.setStrokeColorRGB(0.8, 0.8, 0.8) canvas.setLineWidth(1) # hairline canvas.line(inch, inch, doc.width + inch, inch) canvas.setStrokeColorRGB(0.5, 0.5, 0.5) canvas.setFillColorRGB(0.586, 0.586, 0.586) canvas.drawRightString(doc.width + inch, 0.75 * inch - _TEXT_OFFSET, "Page %d" % (doc.page)) # draw title centered and ellipsized ellipsizedTitle = _ellipsize(doc.getTitle(), splunkLayoutSettings['ellipsizedTitleCount']) ellipsizedTitleWidth = doc.getFontManager().textWidth( ellipsizedTitle, _TITLE_SIZE) textObject = canvas.beginText( inch + doc.width / 2 - ellipsizedTitleWidth / 2, 0.75 * inch - _TEXT_OFFSET) doc.getFontManager().addTextAndFontToTextObject(textObject, ellipsizedTitle, _TITLE_SIZE) canvas.drawText(textObject) timestamp = doc.getTimestamp() timestampWidth = doc.getFontManager().textWidth(timestamp, _DATE_SIZE) textObject = canvas.beginText(inch + doc.width - timestampWidth, inch - _TEXT_OFFSET) doc.getFontManager().addTextAndFontToTextObject(textObject, timestamp, _DATE_SIZE) canvas.drawText(textObject) canvas.restoreState() canvas.saveState() if doc.getLogoDrawing() != None: logoDrawing = doc.getLogoDrawing() renderPDF.draw(logoDrawing, canvas, inch, inch - logoDrawing.height - _LOGO_OFFSET, showBoundary=False) canvas.restoreState()
def drawlines(canvas): canvas.setStrokeColorRGB(0.2,0.5,0.3) canvas.line(0,0,70,70) textobject = canvas.beginText() textobject.setTextOrigin(51.2,749) textobject.textLines(''' LEFT FIELD LABS ''') canvas.drawText(textobject)
def render(self, canvas): if len(self.words) == 1: canvas.setFillColor(self.words[0]['color']) canvas.drawString(self.coords[0], self.coords[1], self.words[0]['txt']) elif len(self.words)>1: txt = canvas.beginText() txt.setTextOrigin(self.coords[0], self.coords[1]) for elt in self.words: txt.setFillColor(elt['color']) txt.textOut(elt['txt']) canvas.drawText(txt)
def drawOn(self, canvas, label=None): canvas.line(self.p1[0], self.p1[1], self.p2[0], self.p2[1]) canvas.circle(*self.p1, r=1*mm, fill=True) canvas.circle(*self.p2, r=1*mm, fill=False) if label is not None: textobject = canvas.beginText() center = ((self.p1 + self.p2)/2.) textobject.setTextOrigin(*center) textobject.setFont("Helvetica", 8) textobject.textOut(label) canvas.drawText(textobject)
def drawOn(self, canvas, label=None): canvas.line(self.p1[0], self.p1[1], self.p2[0], self.p2[1]) canvas.circle(*self.p1, r=1 * mm, fill=True) canvas.circle(*self.p2, r=1 * mm, fill=False) if label is not None: textobject = canvas.beginText() center = ((self.p1 + self.p2) / 2.) textobject.setTextOrigin(*center) textobject.setFont("Helvetica", 8) textobject.textOut(label) canvas.drawText(textobject)
def drawPageNumbers(canvas, style, pages, availWidth, availHeight, dot=' . '): ''' Draws pagestr on the canvas using the given style. If dot is None, pagestr is drawn at the current position in the canvas. If dot is a string, pagestr is drawn right-aligned. If the string is not empty, the gap is filled with it. ''' pages.sort() pagestr = ', '.join([str(p) for p, _ in pages]) x, y = canvas._curr_tx_info['cur_x'], canvas._curr_tx_info['cur_y'] fontSize = style.fontSize pagestrw = stringWidth(pagestr, style.fontName, fontSize) #if it's too long to fit, we need to shrink to fit in 10% increments. #it would be very hard to output multiline entries. #however, we impose a minimum size of 1 point as we don't want an #infinite loop. Ultimately we should allow a TOC entry to spill #over onto a second line if needed. freeWidth = availWidth-x while pagestrw > freeWidth and fontSize >= 1.0: fontSize = 0.9 * fontSize pagestrw = stringWidth(pagestr, style.fontName, fontSize) if isinstance(dot, strTypes): if dot: dotw = stringWidth(dot, style.fontName, fontSize) dotsn = int((availWidth-x-pagestrw)/dotw) else: dotsn = dotw = 0 text = '%s%s' % (dotsn * dot, pagestr) newx = availWidth - dotsn*dotw - pagestrw pagex = availWidth - pagestrw elif dot is None: text = ', ' + pagestr newx = x pagex = newx else: raise TypeError('Argument dot should either be None or an instance of basestring.') tx = canvas.beginText(newx, y) tx.setFont(style.fontName, fontSize) tx.setFillColor(style.textColor) tx.textLine(text) canvas.drawText(tx) commaw = stringWidth(', ', style.fontName, fontSize) for p, key in pages: if not key: continue w = stringWidth(str(p), style.fontName, fontSize) canvas.linkRect('', key, (pagex, y, pagex+w, y+style.leading), relative=1) pagex += w + commaw
def horizontalscale(canvas): textobject = canvas.beginText() textobject.setTextOrigin(3, 2.5 * inch) textobject.setFont("Helvetica-Oblique", 12) horizontalscale = 80 # 100 is default for line in lyrics: textobject.setHorizScale(horizontalscale) textobject.textLine("%s: %s" % (horizontalscale, line)) horizontalscale = horizontalscale + 10 textobject.setFillColorCMYK(0.0, 0.4, 0.4, 0.2) canvas.drawText(textobject)
def draw_address(canvas, text=None): """ Draws the business address """ canvas.setFont('Helvetica', 9) textobject = canvas.beginText(13 * cm, -2.5 * cm) if text is None: text = business_details for line in text: textobject.textLine(line) canvas.drawText(textobject)
def render(self, canvas): if len(self.words) == 1: canvas.setFillColor(self.words[0]['color']) canvas.drawString(self.coords[0], self.coords[1], self.words[0]['txt']) elif len(self.words) > 1: txt = canvas.beginText() txt.setTextOrigin(self.coords[0], self.coords[1]) for elt in self.words: txt.setFillColor(elt['color']) txt.textOut(elt['txt']) canvas.drawText(txt)
def myFirstPage(canvas, doc): PAGE_HEIGHT,PAGE_WIDTH = letter canvas.saveState() canvas.drawImage(fondo, 0,0, PAGE_HEIGHT, PAGE_WIDTH ) canvas.setStrokeColorRGB(1,0,1,alpha=0.1) #canvas.setPageSize(landscape(letter)) canvas.setFont('Arial', 10) canvas.drawString(150, 579, cuenta_cobro.nombre_dependencia) canvas.drawString(215, 558, cuenta_cobro.fecha_transaccion) canvas.drawString(284, 538, cuenta_cobro.nombre_adquiriente) canvas.drawString(90, 513, cuenta_cobro.nit_adquiriente) canvas.drawString(230, 513, cuenta_cobro.direccion_adquiriente) canvas.drawString(492, 513, cuenta_cobro.telefono_adquiriente) canvas.drawString(120, 488, cuenta_cobro.ciudad_adquiriente) # canvas.drawString(285, 474, cuenta_cobro.nombre_beneficiario) canvas.drawString(140, 448, cuenta_cobro.documento_beneficiario) canvas.drawString(365, 448, cuenta_cobro.direccion_beneficiario) canvas.drawString(120, 425, cuenta_cobro.telefono_beneficiario) canvas.drawString(360, 425, cuenta_cobro.email_beneficiario) canvas.drawString(115, 410, cuenta_cobro.ciudad_beneficiario) cuenta_cobro.objeto_contrato = textwrap.fill(cuenta_cobro.objeto_contrato, 80) textobject = canvas.beginText() textobject.setTextOrigin(63, 365) textobject.textLines(cuenta_cobro.objeto_contrato) canvas.drawText(textobject) canvas.drawString(117, 297, cuenta_cobro.no_rpc) canvas.drawString(242, 297, cuenta_cobro.no_cdp) canvas.drawString(392, 297, cuenta_cobro.valor_contrato) canvas.drawString(127, 282, cuenta_cobro.concepto) canvas.drawString(127, 268, cuenta_cobro.valor_concepto) canvas.drawString(95, 255, cuenta_cobro.valor_concepto_letras) SHOW_GRID = False if SHOW_GRID: n = 5 s = 200 #canvas.setStrokeGray(0.90) #canvas.setFillGray(0.90) canvas.setStrokeColorRGB(0,1,1,alpha=0.1) canvas.setFillColorRGB(1,0,1) canvas.setFont('Arial',1) for x in range(s): for y in range(s): canvas.rect(x*n,y*n, width=n, height=n, stroke=1) canvas.drawString(x*n,y*n,"%s,%s" % ((x*n),(y*n)) ) canvas.restoreState()
def createTextBox(canvas, data, horiz, vert, color, font, size): """ Function to draw text """ textobject = canvas.beginText() textobject.setTextOrigin(horiz, vert) textobject.setFont(font, size) textobject.setFillColor(HexColor(color)) for line in data.split("\n"): vert -= size textobject.textLine(line) canvas.drawText(textobject) return vert
def render(self, canvas): canvas.saveState() empty_index = random.sample(range(9), 2) FONT_SIZE = 10 GAP = 5 for index, num in enumerate(self._code): x = index % 3 * (FONT_SIZE + GAP) y = index / 3 * (FONT_SIZE + GAP) if index not in empty_index: t = canvas.beginText(x, y) t.textLine(str(num)) canvas.drawText(t) canvas.restoreState()
def drawCode(canvas, code): """Draws a block of text at current point, indented and in Courier""" canvas.addLiteral("36 0 Td") canvas.setFillColor(colors.blue) canvas.setFont("Courier", 10) t = canvas.beginText() t.textLines(code) c.drawText(t) canvas.setFillColor(colors.black) canvas.addLiteral("-36 0 Td") canvas.setFont("Times-Roman", 10)
def drawCode(canvas, code): """Draws a block of text at current point, indented and in Courier""" canvas.addLiteral('36 0 Td') canvas.setFillColor(colors.blue) canvas.setFont('Courier', 10) t = canvas.beginText() t.textLines(code) c.drawText(t) canvas.setFillColor(colors.black) canvas.addLiteral('-36 0 Td') canvas.setFont('Times-Roman', 10)
def draw_footer(canvas, text=None): """ Draws the invoice footer """ note = ( u'Bank Details: Street address, Town, County, POSTCODE', u'Sort Code: 00-00-00 Account No: 00000000 (Quote invoice number).', u'Please pay via bank transfer or cheque. All payments should be made in CURRENCY.', u'Make cheques payable to Company Name Ltd.', ) if text is None: text = note textobject = canvas.beginText(1 * cm, -27 * cm) for line in text: textobject.textLine(line) canvas.drawText(textobject)
def draw_footer(canvas, text=None): """ Draws the invoice footer """ note = ( 'Bank Details: Street address, Town, County, POSTCODE', 'Sort Code: 00-00-00 Account No: 00000000 (Quote invoice number).', 'Please pay via bank transfer or cheque. All payments should be made in CURRENCY.', 'Make cheques payable to Company Name Ltd.', ) if text is None: text = note textobject = canvas.beginText(1 * cm, -27 * cm) for line in text: textobject.textLine(line) canvas.drawText(textobject)
def write_title_and_credits(canvas, opts, pagesize): canvas.saveState() if pagesize[0] > pagesize[1]: width = pagesize[0] height = pagesize[1] else: width = pagesize[1] height = pagesize[0] canvas.rotate(90) canvas.translate(0, -pagesize[0]) t = canvas.beginText() t.setFont("Times-Roman", 10) l = stringWidth(__COPYRIGHT__, "Times-Roman", 10) t.setTextOrigin(width - l - 5*mm, height+5*mm) t.textOut(__COPYRIGHT__) canvas.setFillColorRGB(0, 0, 0, 0.4) canvas.drawText(t) canvas.setFillColorRGB(0, 0, 0, 1) if opts.title: t = canvas.beginText() t.setTextOrigin(5*mm, height+5*mm) t.setFont("Times-Italic", 20) t.textOut(opts.title) canvas.drawText(t) t = canvas.beginText() t.setTextOrigin(5*mm, -5*mm) t.setFont("Times-Italic", 8) t.textOut(opts.subject) canvas.drawText(t) canvas.restoreState()
def draw_footer(canvas,pdf): """ Draws the invoice footer """ oBank=get_object_or_404(SYSTEM_BANK, pk=1) oCompany=get_object_or_404(SYSTEM_MAIN, pk=1) oCompany=get_object_or_404(SYSTEM_MAIN, pk=1) note = ( u'Bank Details: '+oBank.BankName+'', u'Sort Code: '+oBank.BankSortCode+' Account No: '+oBank.BankAccountNo+' (Quote invoice number).', u"Please pay via bank transfer or cheque. All payments should be made in "+oBank.Curency.Name+"'s.", u'Make cheques payable to '+oCompany.CompanyName+'.', ) textobject = canvas.beginText(1 * cm, -27 * cm) for line in note: textobject.textLine(line) canvas.drawText(textobject)
def draw_page(page, uid, survey_name, canvas: reportlab.pdfgen.canvas.Canvas): draw_qr_data(canvas, 'survey:' + survey_name + ':' + page.name + ':' + uid, 64, (48, height - 64 - 48)) canvas.setFillColorRGB(0.2, 0.2, 0.2) canvas.setStrokeColorRGB(0.2, 0.2, 0.2) canvas.circle(32, 32, 4, stroke=1, fill=1) canvas.circle(32 + 12, 32, 4, stroke=1, fill=1) canvas.circle(32, 32 + 12, 4, stroke=1, fill=1) canvas.circle(width - 32, height - 32, 4, stroke=1, fill=1) canvas.circle(width - 32 - 12, height - 32, 4, stroke=1, fill=1) canvas.circle(width - 32, height - 32 - 12, 4, stroke=1, fill=1) canvas.circle(width - 32, 32, 4, stroke=1, fill=1) canvas.circle(width - 32 - 12, 32, 4, stroke=1, fill=1) canvas.circle(width - 32, 32 + 12, 4, stroke=1, fill=1) canvas.circle(32, height - 32, 4, stroke=1, fill=1) canvas.circle(32 + 12, height - 32, 4, stroke=1, fill=1) canvas.circle(32, height - 32 - 12, 4, stroke=1, fill=1) canvas.setFillColorRGB(0.3, 0.3, 0.3) canvas.drawString(128, height - 67, survey_name + ':' + page.name + ':' + uid) canvas.setFillColorRGB(0.4, 0.4, 0.4) canvas.setStrokeColorRGB(0.2, 0.2, 0.2) canvas.setFont('Courier', 8) for field in page.get_binary_fields(): canvas.circle(field.position[0], height - field.position[1], 5, stroke=1, fill=0) canvas.drawCentredString(field.position[0], height - field.position[1] - 2, field.hint) canvas.setFillColorRGB(0.1, 0.1, 0.1) for text in page.get_text_areas(): if text.rotation != 0: canvas.saveState() canvas.rotate(text.rotation) tobj = canvas.beginText(text.position[0], height - text.position[1]) tobj.setFont(text.fontname, text.fontsize) for line in text.text.split(): tobj.textLine(line) canvas.drawText(tobj) if text.rotation != 0: canvas.restoreState() canvas.showPage()
def contactleftFirstPage(canvas): textobject = canvas.beginText() addrwidth = canvas.stringWidth('510 Victoria Ave, Venice CA 90291','Akkurat',10) urlwidth = canvas.stringWidth('www.leftfieldlabs.com','Akkurat',10) urlx = addrwidth - urlwidth + 18 phonewidth = canvas.stringWidth('424-500-2045','Akkurat',10) phonex = addrwidth - phonewidth + 18 textobject.setTextOrigin(18,75) textobject.setFont('Akkurat',10) textobject.textLine('510 Victoria Ave, Venice CA 90291') yy = textobject.getY() textobject.setTextOrigin(urlx,yy) textobject.textLine('www.leftfieldlabs.com') yyy = textobject.getY() textobject.setTextOrigin(phonex,yyy) textobject.textLine('424-500-2045') canvas.drawText(textobject)
def draw_page_text(self, canvas, heading, body): """Draw main text on page""" textobject = canvas.beginText() textobject.setTextOrigin(2.0*cm, 21.0*cm) textobject.setFont(self.BOLDFONT, 14) heading = heading.replace('\r', '') for line in heading.split('\n'): textobject.textLine(line) textobject.textLine('') textobject.setFont(self.FONT, 12) body = body.replace('\r','') for line in body.split('\n'): textobject.textLine(line) canvas.drawText(textobject)
def DrawString(string, canvas, x, y, lead): textobject = canvas.beginText() textobject.setTextOrigin(x, y) textobject.setLeading(lead) for i in string.split('\n'): if len(i) > 90: i = i.split(" ") s = len(i) / 4 wrd = "" for w in range(3 * s): wrd = wrd + i[w] + " " textobject.textLine(wrd) wrd = "" for w in range(3 * s, len(i)): wrd = wrd + i[w] + " " textobject.textLine(wrd) else: textobject.textLine(i) return canvas.drawText(textobject)
def drawPageNumbers(canvas, style, pages, availWidth, availHeight, dot=' . '): ''' Draws pagestr on the canvas using the given style. If dot is None, pagestr is drawn at the current position in the canvas. If dot is a string, pagestr is drawn right-aligned. If the string is not empty, the gap is filled with it. ''' pages.sort() pagestr = ', '.join([str(p) for p, _ in pages]) x, y = canvas._curr_tx_info['cur_x'], canvas._curr_tx_info['cur_y'] pagestrw = stringWidth(pagestr, style.fontName, style.fontSize) if isinstance(dot, basestring): if dot: dotw = stringWidth(dot, style.fontName, style.fontSize) dotsn = int((availWidth - x - pagestrw) / dotw) else: dotsn = dotw = 0 text = '%s%s' % (dotsn * dot, pagestr) newx = availWidth - dotsn * dotw - pagestrw pagex = availWidth - pagestrw elif dot is None: text = ', ' + pagestr newx = x pagex = newx else: raise TypeError( 'Argument dot should either be None or an instance of basestring.') tx = canvas.beginText(newx, y) tx.setFont(style.fontName, style.fontSize) tx.setFillColor(style.textColor) tx.textLine(text) canvas.drawText(tx) commaw = stringWidth(', ', style.fontName, style.fontSize) for p, key in pages: if not key: continue w = stringWidth(str(p), style.fontName, style.fontSize) canvas.linkRect('', key, (pagex, y, pagex + w, y + style.leading), relative=1) pagex += w + commaw
def horizontalscale(canvas): from reportlab.lib.units import inch textobject = canvas.beginText() textobject.setTextOrigin(3, 2.5 * inch) textobject.setFont("Helvetica-Oblique", 12) horizontalscale = 80 # 100 is default lyrics = [ "azzeertytui", "jkjlkjlkjlllllllllll", "abbbbbbddddkkffffffffffffffffflllllllllllgggggggggggggggggggllll" ] for line in lyrics: textobject.setHorizScale(horizontalscale) textobject.textLine("%s: %s" % (horizontalscale, line)) horizontalscale += 10 textobject.setFillColorCMYK(0.0, 0.4, 0.4, 0.2) textobject.textLines(''' With many apologies to the Beach Boys and anyone else who finds this objectionable ''') canvas.drawText(textobject)
def draw_page(page, uid, survey_name, canvas : reportlab.pdfgen.canvas.Canvas): draw_qr_data(canvas, 'survey:'+survey_name+':'+page.name+':'+uid, 64, (48, height-64-48)) canvas.setFillColorRGB(0.2, 0.2, 0.2) canvas.setStrokeColorRGB(0.2, 0.2, 0.2) canvas.circle(32, 32, 4, stroke=1, fill=1) canvas.circle(32+12, 32, 4, stroke=1, fill=1) canvas.circle(32, 32+12, 4, stroke=1, fill=1) canvas.circle(width - 32, height - 32, 4, stroke=1, fill=1) canvas.circle(width - 32-12, height - 32, 4, stroke=1, fill=1) canvas.circle(width - 32, height - 32-12, 4, stroke=1, fill=1) canvas.circle(width - 32, 32, 4, stroke=1, fill=1) canvas.circle(width - 32-12, 32, 4, stroke=1, fill=1) canvas.circle(width - 32, 32+12, 4, stroke=1, fill=1) canvas.circle(32, height - 32, 4, stroke=1, fill=1) canvas.circle(32+12, height - 32, 4, stroke=1, fill=1) canvas.circle(32, height - 32-12, 4, stroke=1, fill=1) canvas.setFillColorRGB(0.3, 0.3, 0.3) canvas.drawString(128, height - 67, survey_name+':'+page.name+':'+uid) canvas.setFillColorRGB(0.4, 0.4, 0.4) canvas.setStrokeColorRGB(0.2, 0.2, 0.2) canvas.setFont('Courier', 8) for field in page.get_binary_fields(): canvas.circle(field.position[0], height - field.position[1], 5, stroke=1, fill=0) canvas.drawCentredString(field.position[0], height - field.position[1]-2, field.hint) canvas.setFillColorRGB(0.1, 0.1, 0.1) for text in page.get_text_areas(): if text.rotation != 0: canvas.saveState() canvas.rotate(text.rotation) tobj = canvas.beginText(text.position[0], height - text.position[1]) tobj.setFont(text.fontname, text.fontsize) for line in text.text.split(): tobj.textLine(line) canvas.drawText(tobj) if text.rotation != 0: canvas.restoreState() canvas.showPage()
def drawPageNumbers(canvas, style, pages, availWidth, availHeight, dot=' . '): ''' Draws pagestr on the canvas using the given style. If dot is None, pagestr is drawn at the current position in the canvas. If dot is a string, pagestr is drawn right-aligned. If the string is not empty, the gap is filled with it. ''' pages.sort() pagestr = ', '.join([str(p) for p, _ in pages]) x, y = canvas._curr_tx_info['cur_x'], canvas._curr_tx_info['cur_y'] pagestrw = stringWidth(pagestr, style.fontName, style.fontSize) if isinstance(dot, basestring): if dot: dotw = stringWidth(dot, style.fontName, style.fontSize) dotsn = int((availWidth-x-pagestrw)/dotw) else: dotsn = dotw = 0 text = '%s%s' % (dotsn * dot, pagestr) newx = availWidth - dotsn*dotw - pagestrw pagex = availWidth - pagestrw elif dot is None: text = ', ' + pagestr newx = x pagex = newx else: raise TypeError('Argument dot should either be None or an instance of basestring.') tx = canvas.beginText(newx, y) tx.setFont(style.fontName, style.fontSize) tx.setFillColor(style.textColor) tx.textLine(text) canvas.drawText(tx) commaw = stringWidth(', ', style.fontName, style.fontSize) for p, key in pages: if not key: continue w = stringWidth(str(p), style.fontName, style.fontSize) canvas.linkRect('', key, (pagex, y, pagex+w, y+style.leading), relative=1) pagex += w + commaw
def cursormoves1(canvas): textobject = canvas.beginText() #textobject.setLeading(12) textobject.setTextOrigin(inch, 2.5*inch) textobject.setFont("Helvetica-Oblique", 14) lyrics = """well she hit Net Solutions and she registered her own .com site now and filled it up with yahoo profile pics she snarfed in one night now and she made 50 million when Hugh Hefner bought up the rights now and she'll have fun fun fun til her Daddy takes the keyboard away """.split('\n') for line in lyrics: textobject.textLine(line) textobject.setFillGray(0.4) textobject.textLines(''' With many apologies to the Beach Boys and anyone else who finds this objectionable ''') canvas.drawText(textobject)
def contactleftLaterPages(canvas): textobject = canvas.beginText() lflwidth = canvas.stringWidth('LEFT FIELD LABS','Gridnik',12) addrwidth = canvas.stringWidth('510 Victoria Ave, Venice CA 90291','Akkurat',10) urlwidth = canvas.stringWidth('www.leftfieldlabs.com','Akkurat',10) phonewidth = canvas.stringWidth('424-500-2045','Akkurat',10) phonex = addrwidth - phonewidth + 18 lflx = addrwidth - lflwidth + 18 urlx = addrwidth - urlwidth + 18 textobject.setTextOrigin(lflx,75) textobject.setFont('Gridnik',12) textobject.textLine('LEFT FIELD LABS') y = textobject.getY() textobject.setTextOrigin(18,y) textobject.setFont('Akkurat',10) textobject.textLine('510 Victoria Ave, Venice CA 90291') yy = textobject.getY() textobject.setTextOrigin(urlx,yy) textobject.textLine('www.leftfieldlabs.com') yyy = textobject.getY() textobject.setTextOrigin(phonex,yyy) textobject.textLine('424-500-2045') canvas.drawText(textobject)
def write_title_and_credits(canvas, text, nib_width, partitions, angles, pagesize, horizontal = False): canvas.setFillColorRGB(0, 0, 0, 1) if not horizontal: canvas.rotate(90) t = canvas.beginText() if text: canvas.setTitle(text) t.setTextOrigin(10*mm, 3*mm) t.setFont("Times-Italic", 20) t.textOut(text) t.setFont("Times-Italic", 10) t.textOut(" (%smm nib, Partitions:%s, angles:%s)"%(nib_width, partitions, angles)) # canvas.setFillColorRGB(0, 0, 0, 0.2) # w,l = (float(x)/100 for x in A4) # print w,",",l if not horizontal: t.setTextOrigin(10*mm, -pagesize[0]-5*mm) t.setFont("Times-Roman", 10) t.textOut(" Generated using ") t.setFont("Times-Italic", 10) t.textOut("http://calligraffiti.in/rulings") canvas.drawText(t)
def new_textobject(data,canvas,pos_x,pos_y): textobject = canvas.beginText() textobject.setTextOrigin(pos_x,pos_y) textobject.setFont(FONT,FONT_SIZE) textobject.textLines(data,TRIM) return textobject