Ejemplo n.º 1
0
def el_encogedor_de_fuentes_de_doraemon(canvas, fuente, tamannoini, xini, xfin, y, texto, alineacion = -1):
    """
    Comenzando por el tamaño inicial "tamannoini", encoge el texto 
    hasta que quepa en los límites fijados y después lo escribe.
    Convierte el texto por si está en una codificación no soportada.
    Al finalizar, devuelve las propiedades de texto del canvas a 
    su estado original y la fuente a su tamaño inicial.
    NO AVANZA LÍNEA.
    Si alineacion == -1: Alineación a la izquierda. Si 0, centrado y si 1, a la derecha.
    """
    # PLAN: No estaría mal pasar un tamaño mínimo de fuente, y si se alcanza o se supera, cortar la línea con 
    # agregarFila y el último tamaño de fuente válido. Claro que entonces habría que devolver también las líneas 
    # avanzadas, etc...
    canvas.saveState()
    size = tamannoini
    texto = escribe(texto)
    while canvas.stringWidth(texto, fuente, size) > (xfin - xini) and size > 4:
        size -= 1
    canvas.setFont(fuente, size)
    if alineacion == -1:
        canvas.drawString(xini, y, texto)
    elif alineacion == 1:
        canvas.drawRightString(xfin, y, texto)
    elif alineacion == 0:
        canvas.drawCentredString((xfin + xini) / 2.0, y, texto)
    else:
        print "geninformes.py::el_encogedor_de_fuentes_de_doraemon -> Error alineación. Uso alineación a la izquierda por defecto."
        canvas.drawString(xini, y, texto)
    canvas.restoreState()
def printColors(canvas):  
    canvas.setFont("Helvetica",10)
    y = x = 0; dy=inch*1/2.0; dx=1*inch; w=h=dy/2  
    rdx=(dx-w)/2; rdy=h/5.0
    available_paper = 10*inch

    for name, color in colors.getAllNamedColors().iteritems():

    # for [namedcolor, name] in (  
        # 'darkseagreen', 'darkslateblue',
        #  [colors.darkblue, 'darkblue'],
        #  [colors.darkcyan, 'darkcyan'],
        #  [colors.darkolivegreen, 'darkolivegreen'],
        #  [colors.cornflower, 'cornflower'],
        #  [colors.orchid, 'orchid'],
        
        #  [colors.lavenderblush, "lavenderblush"],  
        #  [colors.lawngreen, "lawngreen"],  
        #  [colors.lemonchiffon, "lemonchiffon"],  
        #  [colors.lightblue, "lightblue"],  
        #  [colors.lightcoral, "lightcoral"]):  
        canvas.setFillColor(color)  
        canvas.rect(x+rdx, y+rdy, w, h, fill=1)
        canvas.setFillColor(colors.black)  
        canvas.drawString(x+dx/4 + 1*inch, y+rdy, name)  
        rdy += .2*inch
        available_paper -= (y+rdy)
        if available_paper < 1*inch:
            c.showPage()
            y = x = 0; dy=inch*1/2.0; dx=1*inch; w=h=dy/2  
            rdx=(dx-w)/2; rdy=h/5.0
            available_paper = 10*inch
        def _build_header_canvas(canvas, doc):
            """
            Draw the document header.

            Local function to be passed later to output_doc.build().
            Reportlab automatically passes args when called.
            """
            # The header function to be passed later to output_doc.build()
            # Set up positions
            header_y_position = (11 * units.inch) - 45
            page_number = doc.page
            if page_number % 2 == 0:
                # Left-hand page
                page_number_x_position = 60
            else:
                # Right-hand page
                page_number_x_position = (8.5 * units.inch) - 60
            canvas.saveState()
            canvas.setFont(self.paragraph_style.fontName,
                           self.paragraph_style.fontSize)
            if self.title:
                canvas.drawCentredString((8.5 * units.inch) / 2,
                                         header_y_position,
                                         self.title)
            canvas.drawString(page_number_x_position, header_y_position,
                              str(page_number))
            canvas.restoreState()
Ejemplo n.º 4
0
 def myFirstPage(self, canvas, doc):
     canvas.saveState()
     canvas.setFont('Times-Roman',9)
     canvas.drawString(inch, 0.75 * inch, "Page 1 / %s" % pageinfo)
     self.headerTable.wrapOn(canvas, 540, height)
     self.headerTable.drawOn(canvas, *coord(1.0, 1.5, cm))
     canvas.restoreState()
Ejemplo n.º 5
0
 def myFirstPage(canvas, doc):
     canvas.saveState()
     canvas.setFont('Times-Bold', 16)
     canvas.drawCentredString(PAGE_WIDTH / 2.0, PAGE_HEIGHT - 108, Title)
     canvas.setFont('Times-Roman', 9)
     canvas.drawString(inch, 0.75 * inch, "First Page / %s" % pageinfo)
     canvas.restoreState()
Ejemplo n.º 6
0
def _draw_subsection(canvas, yc, title_left, title_middle, title_right, text_tuples):
    if title_left or title_middle or title_right:
        canvas.setFont(SUBSECTION_TITLE_FONT, SUBSECTION_FONT_SIZE)
        title_y = yc - SUBSECTION_FONT_SIZE
        if title_left:
            title_x = H_TEXT_MARGIN
            canvas.drawString(title_x, title_y, title_left)
        if title_middle:
            title_x = RESUME_PAGE_SIZE[0] / 2
            canvas.drawCentredString(title_x, title_y, title_middle)
        if title_right:
            title_x = RESUME_PAGE_SIZE[0] - H_TEXT_MARGIN
            canvas.drawRightString(title_x, title_y, title_right)        
        yc = title_y - V_SEPARATOR
        
    canvas.setFont(SUBSECTION_FONT, SUBSECTION_FONT_SIZE)
    for (draw_bullet, text) in text_tuples:
        if draw_bullet:
            text = u"•  " + unicode(text)
            
        lines = _break_text(text, RESUME_PAGE_SIZE[0] - (2*H_TEXT_MARGIN + SUBSECTION_H_INDENT), SUBSECTION_FONT, SUBSECTION_FONT_SIZE)
        
        line_x = H_TEXT_MARGIN + SUBSECTION_H_INDENT                
        for line in lines:
            line_y = yc - SUBSECTION_FONT_SIZE        
            canvas.drawString(line_x, line_y, line)
            yc = line_y - V_SEPARATOR
    
    return yc - SUBSECTION_V_SPACER
Ejemplo n.º 7
0
Archivo: models.py Proyecto: B-Rich/M2M
 def docPage(canvas,doc):
     canvas.saveState()
     canvas.setFont('Times-Bold', 10)
     canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT - (.25 * inch), Title)
     canvas.setFont('Times-Roman',9)
     canvas.drawString(7 * inch, .75 * inch, "Page %d" % (doc.page,))
     canvas.restoreState()
Ejemplo n.º 8
0
    def myPage(canvas, doc):
        canvas.saveState()  # save the current state
        canvas.setFont('InconsolataBold', 16)  # set the font for the name
        canvas.drawString(
            .4 * inch,
            HEIGHT - (.4 * inch),
            contact['name'])  # draw the name on top left page 1
        canvas.setFont('Inconsolata', 8)  # sets the font for contact
        canvas.drawRightString(
            WIDTH - (.4 * inch),
            HEIGHT - (.4 * inch),
            contact['website'])  
        canvas.line(.4 * inch, HEIGHT - (.47 * inch), 
            WIDTH - (.4 * inch), HEIGHT - (.47 * inch))
        canvas.drawString(
            .4 * inch,
            HEIGHT - (.6 * inch),
            contact['phone'])
        canvas.drawCentredString(
			WIDTH / 2.0,
			HEIGHT - (.6 * inch),
			contact['address'])
        canvas.drawRightString(
			WIDTH - (.4 * inch),
			HEIGHT - (.6 * inch),
			contact['email'])
        # restore the state to what it was when saved
        canvas.restoreState()
Ejemplo n.º 9
0
def contig_ticker(canvas, feature, cLen, Y0, offset, offset_mode):
    """Draw contig separators."""
    # get contig name
    name = feature.qualifiers.get('id')[0]
    # take start and end points
    location = feature.location
    Zs = location.nofuzzy_start
    Ze = location.nofuzzy_end
    # calculate offset coordinates
    if offset_mode == 'loop':
        offZs = offset_coord(Zs, cLen, offset)
        offZe = offset_coord(Ze, cLen, offset)
    elif offset_mode == 'nudge':
        offZs = nudge_coord(Zs, offset)
        offZe = nudge_coord(Ze, offset)
    else:
        offZs = Zs
        offZe = Ze
    xs, xe = offZs*u, offZe*u
    # set Y axis coordinates
    y0 = Y0-dop*3.5
    # draw
    canvas.setLineWidth(2)
    ttl = canvas.beginPath()
    ttl.moveTo(xs,y0)
    ttl.lineTo(xs,y0-h*4)
    ttl.lineTo(xs+dop,y0-h*4)
    canvas.drawPath(ttl, stroke=1, fill=0)
    canvas.setFont(bFont, NfSize)
    canvas.drawString(xs+dop*2, y0-h*4.5, name)
    canvas.setFont(rFont, SfSize)
    canvas.drawString(xs+dop*2,y0-h*8,"".join(["[",str(Zs),"-",str(Ze),"]"]))
    canvas.setFont(rFont, NfSize)
    ttl.close()
Ejemplo n.º 10
0
Archivo: pdf.py Proyecto: wichmann/bbss
def create_first_page(canvas, doc):
    canvas.saveState()
    canvas.setFont('Helvetica', 16)
    canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT-58, TITLE)
    canvas.setFont('Helvetica', 10)
    canvas.drawString(BORDER_HORIZONTAL, BORDER_VERTICAL, TITLE)
    canvas.drawRightString(PAGE_WIDTH-BORDER_HORIZONTAL , BORDER_VERTICAL, "Seite 1")
    canvas.restoreState()
Ejemplo n.º 11
0
 def draw_amount(self, canvas):
     txt = {'de': 'Stückzahl: {0}', 'en': 'Amount: {0}'}
     txt = txt[self.lang].format(self.amount)
     canvas.drawString(self.center, self.y, txt)
     canvas.rect(
         self._rect_x(self.center), self._rect_y(self.y), self.rect_width,
         self.rect_height)
     self.y -= self.y_decrease
Ejemplo n.º 12
0
 def draw_connector(self, canvas):
     txt = {'de': 'Anschluss: {0}', 'en': 'Connector: {0}'}
     txt = txt[self.lang].format(self.connector)
     canvas.drawString(self.center, self.y, txt)
     canvas.rect(
         self._rect_x(self.center), self._rect_y(self.y), self.rect_width,
         self.rect_height)
     self.y -= self.y_decrease
Ejemplo n.º 13
0
 def draw_cable(self, canvas):
     txt = {'de': 'Kabellänge: {0}', 'en': 'Cablelength: {0}'}
     txt = txt[self.lang].format(self.cable)
     canvas.drawString(self.center, self.y, txt)
     canvas.rect(
         self._rect_x(self.center), self._rect_y(self.y), self.rect_width,
         self.rect_height)
     self.y -= self.y_decrease
Ejemplo n.º 14
0
 def draw_tubeoffset(self, canvas):
     txt = {'de': 'Rohrüberstand: {0}cm', 'en': 'Clearance: {0}cm'}
     txt = txt[self.lang].format(self.offset)
     canvas.drawString(self.center, self.y, txt)
     canvas.rect(
         self._rect_x(self.center), self._rect_y(self.y), self.rect_width,
         self.rect_height)
     self.y -= self.y_decrease
Ejemplo n.º 15
0
 def draw_tubelength(self, canvas):
     txt = {'de': 'Rohrlänge: {0}cm', 'en': 'Tubelength: {0}cm'}
     txt = txt[self.lang].format(self.tube)
     canvas.drawString(self.center, self.y, txt)
     canvas.rect(
         self._rect_x(self.center), self._rect_y(self.y), self.rect_width,
         self.rect_height)
     self.y -= self.y_decrease
Ejemplo n.º 16
0
    def draw_intro_text(self, canvas):
        txt = {
            'de': 'Durch die gewählten Messpunkte ergab sich folgende \
Konfiguration:',
            'en': 'Given measuring points lead to the following \
configuration:'}
        canvas.drawString(self.center, self.y, txt[self.lang])
        self.y -= 2*self.y_decrease
Ejemplo n.º 17
0
def addText(canvas,element,styles):
	for run in element.getElementsByTagName("sn:r"):
		if(len(run.getElementsByTagName("sn:t")) > 0):
			##TODO: support italic, bold and underlined text
			charStyle = styles["Character" + run.getAttributeNode("sn:rStyle").value]
			text=run.getElementsByTagName("sn:t")[0].firstChild.nodeValue
			canvas.setFont("Helvetica",charStyle.size)
			canvas.setFillColor(charStyle.color)
			canvas.drawString(40,810-charStyle.size,text)
Ejemplo n.º 18
0
def genBarcode(code, value, canvas, scale):
    dr = createBarcodeDrawing(code, value=value, humanReadable=True)
    dr.renderScale = scale
    bounds = dr.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    dr.drawOn(canvas, (297*mm)/2-width*scale/2, (210*mm)/2-height*scale/2)
    canvas.drawString(1*mm, 1*mm, "generated at "+str(datetime.now()) + " from "+request.url)
    canvas.showPage()
Ejemplo n.º 19
0
def _draw_section_title(canvas, yc, title):
    title = title.upper()
    title_x = H_TEXT_MARGIN
    title_y = yc - SECTION_V_SPACE - SECTION_FONT_SIZE
    line_y = title_y - V_SEPARATOR
    canvas.setFont(SECTION_FONT, SECTION_FONT_SIZE)
    canvas.drawString(title_x, title_y, title)
    canvas.line(H_TEXT_MARGIN - H_LINE_MARGIN_OFFSET, line_y, RESUME_PAGE_SIZE[0] - (H_TEXT_MARGIN - H_LINE_MARGIN_OFFSET), line_y)
    return line_y# - V_SEPARATOR
Ejemplo n.º 20
0
def framePage(canvas, title, pos):
    canvas.setFont('Times-Roman', 15)
    canvas.drawString(inch, pos * inch, title)
    canvas.setFont('Times-Roman', 10)
    canvas.drawCentredString(4.135 * inch, 0.75 * inch,
                            'Página %d' % canvas.getPageNumber())
    #reset carefully afterwards
    canvas.setLineWidth(1)
    canvas.setStrokeColorRGB(0, 0, 0)
Ejemplo n.º 21
0
def base_draw(canvas, cName, cLen, feats, key, dop_Y, Y0, X_shift,
             map_mode, annot_cnt, offset, offset_mode, seq_len,
             annot_mode, fct_flags, fct_colors) :
    """Draw contig baseline and features."""
    # draw plasmid baseline
    baseliner(cLen, canvas, Y0, offset, offset_mode)
    # label the baseline with plasmid name and size
    labeller(cName, cLen, canvas, Y0)
    # label the annotations list
    Y_annot = 0
    if map_mode != 'n':
        canvas.setFont(bFont, LfSize)
        canvas.drawString(X_shift, y_adj, cName)
    canvas.setFont(rFont, SfSize)
    Y_annot +=2
    # filter and draw annotation features
    ORFcnt = 0
    shift_flag = False
    for feature in feats :
        if feature.type == 'contig':
            contig_ticker(canvas, feature, cLen, Y0, offset, offset_mode)
        elif feature.type == 'ref_seg':
            ref_ticker(canvas, feature, cLen, Y0, offset, offset_mode)
        elif feature.type == 'CDS' or feature.type == 'cds':
            ORFcnt += 1
            # determine functional category color
            try:
                annot = feature.qualifiers.get(key)[0]
            except TypeError:
                annot = 'none'
            fct_key = annot_color(fct_flags, annot)
            color_hex = HexColor(fct_colors[fct_key][0])
            # calculate coordinates for canvas
            featL, midLZ, coords, split_flag = orf_coords(feature, Y0, cLen,
                                                         offset, offset_mode)
            # check for CDS sitting across the origin
            if split_flag:
                # split coords
                coords1, featL1, coords2, featL2 = orf_split(coords, cLen)
                # draw square feature
                orf_eus(canvas, featL1, coords1, color_hex, shape='square')
                # draw arrow feature
                orf_eus(canvas, featL2, coords2, color_hex, shape=None)
            else:
                # draw arrow feature
                orf_eus(canvas, featL, coords, color_hex, shape=None)
            # write annotation line and CDS number
            if map_mode != 'n':
                if map_mode == 'single' and Y_annot-1 > annot_cnt/2:
                    X_shift = seq_len/2
                    if not shift_flag:
                        Y_annot -= annot_cnt/2
                        shift_flag = True
                Y_annot = orf_annot(canvas, cLen, annot, Y_annot, ORFcnt,
                                   Y0+dop_Y, midLZ, X_shift, split_flag,
                                   annot_mode)
Ejemplo n.º 22
0
    def myFirstPage(canvas, doc):
        Title = ""
        pageinfo = "Secretaria de Desarrollo Territorial y Bienestar Social - Eje Adulto Mayor"
        canvas.saveState()

        #canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT-108, Title)
        canvas.setFont('Helvetica',8)
        canvas.drawString(inch, 0.5 * inch,"{0} / {1}".format(pageinfo,datetime.now().strftime('%d-%m-%Y %H:%M:%S')))

        canvas.restoreState()
Ejemplo n.º 23
0
def myFirstPage(canvas, doc):
    PAGE_HEIGHT = defaultPageSize[1]
    PAGE_WIDTH = defaultPageSize[0]
    pageinfo = "DIAGNOSIS REPORT"
    canvas.saveState()
    canvas.setFont('Times-Bold', 16)
    canvas.drawCentredString(PAGE_WIDTH / 2.0, PAGE_HEIGHT - 100, "DIAGNOSIS REPORT")
    canvas.setFont('Times-Roman', 9)
    canvas.drawString(inch, 0.75 * inch, "Page 1 / %s" % pageinfo)
    canvas.restoreState()
Ejemplo n.º 24
0
	def setFirstPage(self,canvas,doc):
		canvas.saveState()
		canvas.setFont('Times-Bold', 25)
		canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT - 100, 'Relatorio')
		canvas.setFont('Times-Bold', 22)
		canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT - 130, self.title)
		canvas.setFont('Times-Roman',9)
		canvas.drawString(inch, 0.75*inch, '1')
		#canvas.setFont(self.fonts[0],self.sizes[0])
		canvas.restoreState()
Ejemplo n.º 25
0
 def myLaterPages(canvas, doc):
     from reportlab.lib.colors import red
     PAGE_HEIGHT = canvas._pagesize[1]
     canvas.saveState()
     canvas.setStrokeColor(red)
     canvas.setLineWidth(5)
     canvas.line(66,72,66,PAGE_HEIGHT-72)
     canvas.setFont('Times-Roman',12)
     canvas.drawString(4 * inch, 0.75 * inch, "Page %d" % doc.page)
     canvas.restoreState()
   def pageFooter(self, canvas, doc):
      canvas.saveState()
      canvas.setFont( self.footerFontName, self.footerFontSize, self.footerFontLeading )

      # draw the doc info
      canvas.drawString ( self.footerLeftEdge, self.footerHeight, self.pageInfo )

      # draw the page number
      canvas.drawRightString ( self.footerRightEdge, self.footerHeight, "Page {0}".format (doc.page) )
      canvas.restoreState()
Ejemplo n.º 27
0
Archivo: models.py Proyecto: B-Rich/M2M
 def docPage(canvas,doc):
     canvas.saveState()
     canvas.setFont('Times-Bold', 10)
     canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT - (.25 * inch), Title)
     canvas.setFont('Times-Roman',9)
     canvas.drawString(7 * inch, .75 * inch, "Page %d" % (doc.page,))
     canvas.restoreState()
     
     def __unicode__(self):
         return u"Undefined Problem: %d" % self.file.id        
Ejemplo n.º 28
0
 def first_page(self, canvas, doc):
     
     canvas.setFont("Times-Roman", 10)
     canvas.drawString(65,720,"Finance report for : %s %s" %(datetime.date.today().strftime("%B"), datetime.date.today().strftime("%Y")))
     canvas.drawString(65,705,'Report generated on : %s' %str("{:%d.%m.%Y}".format(datetime.datetime.now())))
     canvas.setLineWidth(.2)
     canvas.line(50,695,540,695)
     
     page_num = canvas.getPageNumber()
     text = "Page #%s" % page_num
     canvas.drawRightString(200*mm, 20*mm, text)
Ejemplo n.º 29
0
def fonts(canvas):
    from reportlab.lib.units import inch
    text = "Now is the time for all good men to..."
    x = 1.8 * inch
    y = 2.7 * inch
    for font in canvas.getAvailableFonts():
        canvas.setFont(font, 10)
        canvas.drawString(x, y, text)
        canvas.setFont("Helvetica", 10)
        canvas.drawRightString(x - 10, y, font + ":")
        y = y - 13
Ejemplo n.º 30
0
    def later_pages(self, canvas, doc):

        canvas.saveState()
        canvas.setFont('Courier', 9)
        canvas.drawString(inch, 0.75 * inch,"%s - %s" % (self.today.strftime('%d/%m/%Y'),
                                                         canvas.getPageNumber()))
        canvas.drawString(490,0.75 * inch,"his Majesty")
       
        canvas.setFont('Times-Bold',8)
        canvas.drawCentredString(0.5 * A4[0],0.5 * inch,"%s" % self.app.GetAppName())
        canvas.restoreState()
Ejemplo n.º 31
0
def create_first_page(canvas, doc):
    canvas.saveState()
    canvas.setFont('Helvetica', 16)
    canvas.drawCentredString(PAGE_WIDTH / 2.0, PAGE_HEIGHT - 98, TITLE)
    canvas.setFont('Helvetica', 11)
    canvas.drawCentredString(PAGE_WIDTH / 2.0, PAGE_HEIGHT - 130, AUTHOR)
    canvas.setFont('Helvetica', 10)
    canvas.drawString(BORDER_HORIZONTAL, BORDER_VERTICAL, TITLE)
    canvas.drawRightString(PAGE_WIDTH - BORDER_HORIZONTAL, BORDER_VERTICAL,
                           "Seite 1")
    canvas.restoreState()
Ejemplo n.º 32
0
    def docPage(canvas, doc):
        canvas.saveState()
        canvas.setFont('Times-Bold', 10)
        canvas.drawCentredString(PAGE_WIDTH / 2.0, PAGE_HEIGHT - (.25 * inch),
                                 Title)
        canvas.setFont('Times-Roman', 9)
        canvas.drawString(7 * inch, .75 * inch, "Page %d" % (doc.page, ))
        canvas.restoreState()

        def __unicode__(self):
            return u"Undefined Problem: %d" % self.file.id
Ejemplo n.º 33
0
def fonts(canvas):
    from reportlab.lib.units import inch
    text = "Now is the time for all good men to..."
    x = 1.8*inch
    y = 2.7*inch
    for font in canvas.getAvailableFonts():
        canvas.setFont(font, 10)
        canvas.drawString(x,y,text)
        canvas.setFont("Helvetica", 10)
        canvas.drawRightString(x-10,y, font+":")
        y = y-13
Ejemplo n.º 34
0
def draw_footer(canvas, font_size, y):
    text1 = 'Created with ' + PROGRAM_FULLNAME
    text2 = PROGRAM_WEBSITE
    text2_w = stringWidth(text2, FONT_NAME, FOOTER_FONT_SIZE)
    text2_x = PAGE_SIZE[0] - GRID_OFFSET - text2_w
    canvas.setFont(FONT_NAME, font_size)
    canvas.drawString(GRID_OFFSET, y, text1)
    canvas.drawString(text2_x, y, text2)
    y -= 0.2 * FONT_SIZE
    canvas.linkURL('www.' + text2, (text2_x, y, \
                    text2_x + text2_w, y + 0.8*FONT_SIZE))
Ejemplo n.º 35
0
 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)
Ejemplo n.º 36
0
def _draw_address_lines(canvas, address_lines):
    yc = RESUME_PAGE_SIZE[1] - V_TOP_MARGIN
    canvas.setFont(CONTACT_FONT, CONTACT_FONT_SIZE)
    addr_x = H_TEXT_MARGIN
    
    for address in address_lines:
        addr_y = yc - CONTACT_FONT_SIZE
        canvas.drawString(addr_x, addr_y, address)
        yc = addr_y - V_SEPARATOR
        
    return yc
Ejemplo n.º 37
0
def build_filled_pdf_page(page_data: PageData, values: Dict[str, Any]) -> PageObject:
    packet = io.BytesIO()
    canvas = reportlab.pdfgen.canvas.Canvas(
        packet, reportlab.lib.pagesizes.letter, initialFontName="Times-Roman", initialFontSize=14
    )
    for position, emplacement_data in page_data.items():
        canvas.drawString(*position, str(values.get(emplacement_data.name, ""))[: emplacement_data.line_size])
    canvas.showPage()
    canvas.save()
    packet.seek(0)
    return PyPDF2.PdfFileReader(packet).getPage(0)
Ejemplo n.º 38
0
Archivo: invoice.py Proyecto: ses4j/ts
def draw_header(canvas):
    """ Draws the invoice header """
    canvas.setStrokeColorRGB(176 / 255., 196 / 255., 222 / 255.)
    # canvas.setStrokeColorRGB(0.9, 0.5, 0.2)
    canvas.setFillColorRGB(0.2, 0.2, 0.2)
    canvas.setFont('Helvetica', 16)
    canvas.drawString(18 * cm, -1 * cm, 'Invoice')
    if consultant_logo_filename:
        canvas.drawInlineImage(consultant_logo_filename, 1 * cm, -1 * cm, 250,
                               16)
    canvas.setLineWidth(4)
    canvas.line(0, -1.25 * cm, 21.7 * cm, -1.25 * cm)
Ejemplo n.º 39
0
 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)
Ejemplo n.º 40
0
def Header(canvas, doc):
    canvas.saveState()
    #canvas.drawImage( current_app.config["APP_PATH"] + '/src/etc/img/logo1.png', 10, 800 , mask='auto')
    #canvas.drawImage( current_app.config["APP_PATH"] + '/src/etc/img/logo2.png', 430, 800, width=140, height=25, mask='auto')

    canvas.setStrokeColor('#ABAAAB')
    canvas.line(A4[0] - 700, A4[1] - 53, A4[0] - 0, A4[1] - 53)
    canvas.setFillColor('#666666')
    canvas.setFont('HelveticaNeueBold', 20)
    canvas.drawString(10, A4[1] - 77, form['header']['name'])
    canvas.line(A4[0] - 700, A4[1] - 90, A4[0] - 0, A4[1] - 90)
    canvas.restoreState()
Ejemplo n.º 41
0
def labeller(cName, cLen, canvas, Y_map) :
    """Label baselines with genome/contig name and size."""
    canvas.setFillColor(black)
    y0 = Y_map
    x0 = -pNsize                # retreat into the left margin to write out name and size
    y1 = y0 + ck_vsp/10         # bump name up a bit from BL level
    y2 = y0 - ck_vsp            # bump size down a bit from BL level
    pLenStr = str(float(cLen)/1000) # converts number to suitable form
    canvas.setFont(bFont,LfSize)
    canvas.drawString(x0,y1,cName)
    canvas.setFont(rFont,NfSize)
    canvas.drawString(x0,y2,pLenStr+' kb')
Ejemplo n.º 42
0
def genBarcode(code, value, canvas, scale):
    dr = createBarcodeDrawing(code, value=value, humanReadable=True)
    dr.renderScale = scale
    bounds = dr.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    dr.drawOn(canvas, (297 * mm) / 2 - width * scale / 2,
              (210 * mm) / 2 - height * scale / 2)
    canvas.drawString(
        1 * mm, 1 * mm,
        "generated at " + str(datetime.now()) + " from " + request.url)
    canvas.showPage()
Ejemplo n.º 43
0
 def myFirstPage(canvas, doc):
     from reportlab.lib.colors import red
     PAGE_HEIGHT = canvas._pagesize[1]
     canvas.saveState()
     canvas.setStrokeColor(red)
     canvas.setLineWidth(5)
     canvas.line(66,72,66,PAGE_HEIGHT-72)
     canvas.setFont(_baseFontNameB,24)
     canvas.drawString(108, PAGE_HEIGHT-108, "TABLE OF CONTENTS DEMO")
     canvas.setFont(_baseFontName,12)
     canvas.drawString(4 * inch, 0.75 * inch, "First Page")
     canvas.restoreState()
Ejemplo n.º 44
0
    def _draw_back(self, canvas):
        super()._draw_back(canvas)

        # Challenge
        self.fonts.set_font(canvas, "challenge")
        canvas.drawString(
            self.WIDTH + self.BORDER_FRONT[Border.LEFT], self.CHALLENGE_BOTTOM,
            "Challenge {} ({} XP)".format(self.challenge_rating,
                                          self.experience_points))
        ### Source
        self.fonts.set_font(canvas, "text")
        canvas.drawString(*self.SOURCE_LOCATION, self.source)
Ejemplo n.º 45
0
def drawStrings(canvas, x, y, *lines):
    step = 0.5*cm
    for line in lines:
        if isinstance(line, int):
            if line < 0:
                canvas.setFont('Helvetica-Bold', abs(line))
            else:
                canvas.setFont('Helvetica', abs(line))
            step = abs(line) / 24.0 * cm
            continue
        canvas.drawString(x, y, line)
        y -= step
Ejemplo n.º 46
0
 def draw(self):
     canvas = self.canv
     # Texte label
     canvas.setFillColorRGB(0, 0, 0)
     canvas.setFont("Helvetica", 9)
     canvas.drawString(
         15, 1, "%s : %s" % (self.label, minutesEnHeures(self.totalHeures)))
     # Carré de couleur
     if self.couleur != None:
         r, g, b = ConvertCouleur(FormateCouleur(self.couleur))
         canvas.setFillColorRGB(r, g, b)
         canvas.rect(0, 0, 10, 10, fill=1)
Ejemplo n.º 47
0
def get_stamp_pdf(PROJ_NAME, PAGE_NO):
    from reportlab.pdfgen import canvas
    out_path = tempfile.mktemp(suffix=".pdf")
    canvas = canvas.Canvas(out_path, pagesize=A4)
    canvas.setLineWidth(.3)
    canvas.setFont('Segoe UI', 8)
    canvas.setStrokeColorRGB(0, 0, 0)
    canvas.setFillColorRGB(0, 0, 0)
    canvas.drawString(30, 10, "Feedback Report for {0}".format(PROJ_NAME))
    canvas.drawString(540, 10, "Page {0}".format(PAGE_NO))
    canvas.save()
    return out_path
Ejemplo n.º 48
0
Archivo: report.py Proyecto: xfxf/dabo
	def printBandOutline(self, canvas, text):
		""" Draw a dotted rectangle around the entire band, and type a small faded
		caption at the origin of the band.
		"""
		canvas.saveState()
		canvas.setLineWidth(0.1)
		canvas.setStrokeColorRGB(0.8, 0.5, 0.7)
		canvas.setDash(1, 2)
		canvas.rect(self.x, self.y, self.width, self.height)
		canvas.setFont("Helvetica", 8)
		canvas.setFillColor((0.6, 0.8, 0.7))
		canvas.drawString(self.x, self.y, text)
		canvas.restoreState()
def draw_sticker_items(canvas, start_x=100, start_y=750, step=20):
    new_y = start_y
    sticker_items = OrderedDict({
        "name": "Elevate Crop Top",
        "color": "Color: Black",
        "size": "Size: XS",
        "sku": "SKU: ECTPU-B-XS"
    })
    for i, sticker_item in enumerate(sticker_items):
        new_y = start_y - i * step
        canvas.drawString(start_x, new_y, sticker_items[sticker_item])

    return new_y
Ejemplo n.º 50
0
    def _headerfooter(self, canvas, doc):
        canvas.setLineWidth(1)

        canvas.saveState()
        canvas.setFont('Helvetica', 9)
        canvas.drawString(4, 410, "%s" % self.title)
        canvas.line(2, 407, 295, 407)
        canvas.setFont('Helvetica', 6)
        canvas.line(2, 10, 295, 10)
        canvas.drawString(
            4, 4,
            "PyAeromanger 14/2015 by zerodine GmbH - Thomas Spycher @tspycher")
        canvas.restoreState()
Ejemplo n.º 51
0
    def addPageNumber(canvas, doc):
        """
		Add the page numbers to the document
		"""
        width, height = A4  # this is useful when defining where to plot something on the page

        page_num = canvas.getPageNumber()
        text = "%s" % page_num
        header = "TIC {}".format(tic)

        canvas.setFont('Helvetica', 8)
        canvas.drawString(width * 0.85, height * 0.95, header)
        canvas.drawRightString(200 * mm, 10 * mm, text)
Ejemplo n.º 52
0
    def draw_later_header(self, canvas, doc):
        header_string = f"{self.title} - {self.filename}".replace(
            "&lt;", "<").replace("&gt;", ">")

        canvas.setStrokeColorRGB(0, 0, 0)
        canvas.setLineWidth(0.5)
        canvas.setFont(_baseFontName, 10)
        print(
            f"Later Header Height: {self.bottomMargin + self.inner_height + 5}"
        )
        canvas.drawString(self.leftMargin + 5,
                          self.inner_height + self.bottomMargin + 5,
                          header_string)
Ejemplo n.º 53
0
 def draw_main_doc_header(canvas, pdf):
     """ Draws the invoice header """
     canvas.saveState()
     canvas.translate(0, 29.7 * cm)
     canvas.setFont('Helvetica', 10)
     canvas.setStrokeColorRGB(0.9, 0.5, 0.2)
     canvas.setFillColorRGB(0.2, 0.2, 0.2)
     canvas.setFont('Helvetica', 16)
     canvas.drawString(18 * cm, -1 * cm, 'Invoice')
     canvas.drawInlineImage(INV_LOGO, 1 * cm, -1 * cm, 25, 25)
     canvas.setLineWidth(4)
     canvas.line(0, -1.25 * cm, 21.7 * cm, -1.25 * cm)
     canvas.restoreState()
Ejemplo n.º 54
0
def mensaje_monotributista(canvas, mensaje):
    top = height - 243*mm
    box_width = width / 2 + 2*margin
    box_height = 20*mm

    canvas.saveState()
    canvas.rect(margin, top, box_width, box_height, stroke=1, fill=0)
    canvas.setFont(font_std, 11)

    for line, i in zip(mensaje, list(range(len(mensaje)))):
        canvas.drawString(margin * 2, top - margin - i*15 + box_height, line)

    canvas.restoreState()
Ejemplo n.º 55
0
 def place_doc_title(self, canvas, doc):
     """places the title at the location defined in design.json Args:
         canvas (Canvas): canvas object from reportlab
         doc (string): Title of the document
     """
     x = self.design["doc title"]["x"]
     y = self.design["doc title"]["y"]
     size = self.design["doc title"]["size"]
     doc_title = self.doc_metdata["doc title"]
     # Place title:
     canvas.saveState()
     canvas.setFont("Helvetica-Bold", 16)
     canvas.drawString(x, y, doc_title)
     canvas.restoreState()
Ejemplo n.º 56
0
def firma_actasIntegrales(canvas, doc):
    ##########-------------------- Pie de Pagina del reporte ###########
    canvas.saveState()
    canvas.setStrokeColor(black)
    canvas.setFont("Helvetica-BoldOblique", 6.5)
    canvas.drawString(2.7 * inch, 2.37 * cm, 'Firma y Sello Decanato')
    canvas.drawString(4.35 * inch, 2.37 * cm, 'Firma y Sello Coordinación')
    #canvas.drawString(9.3*cm, 2.37*cm, 'Profesor:')
    #canvas.drawString(15*cm, 2.37*cm, u'Cédula:')
    #canvas.drawString(11.3*cm, 1.0*cm, 'Firma')
    #canvas.drawString(15*cm, 1.0*cm, 'Fecha')
    canvas.grid([2.3 * inch, 4.1 * inch, 5.8 * inch],
                [0.23 * inch, 1.06 * inch])
    canvas.restoreState()
Ejemplo n.º 57
0
    def header(self, canvas, doc, growing_year, cur_date):
        """Create the header of the document

        Parameters
        ----------
        canvas
        doc
        growing_year: int
        cur_date: str, with the current date

        """
        canvas.saveState()
        canvas.drawString(30, 750, self.tr('Simple report from GeoDataFarm'))
        canvas.drawString(
            30, 733,
            self.tr('For the growing season of ') + str(growing_year))
        canvas.drawImage(self.plugin_dir + '\\img\\icon.png',
                         500,
                         765,
                         width=50,
                         height=50)
        canvas.drawString(500, 750, 'Generated:')
        canvas.drawString(500, 733, cur_date)
        canvas.line(30, 723, 580, 723)
        #w, h = content.wrap(doc.width, doc.topMargin)
        #content.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin - h)
        canvas.restoreState()
Ejemplo n.º 58
0
 def func(canvas, doc):
     width, height = letter
     margin = 0.66 * 72
     canvas.saveState()
     canvas.setFillColor('gray')
     canvas.drawString(margin, height - margin, "CONFIDENTIAL")
     canvas.drawRightString(width - margin, height - margin,
                            str(timezone.now()))
     canvas.drawString(
         margin,
         margin,
         f"Intended for: Title IX Coordinator {recipient}",
     )
     canvas.restoreState()
Ejemplo n.º 59
0
def framePage(canvas,doc):
    #canvas.drawImage("snkanim.gif", 36, 36)
    canvas.saveState()
    canvas.setStrokeColorRGB(1,0,0)
    canvas.setLineWidth(5)
    canvas.line(66,72,66,PAGE_HEIGHT-72)

    canvas.setFont('Times-Italic',12)
    canvas.drawRightString(523, PAGE_HEIGHT - 56, "Platypus User Guide and Test Script")

    canvas.setFont('Times-Roman',12)
    canvas.drawString(4 * inch, 0.75 * inch,
                        "Page %d" % canvas.getPageNumber())
    canvas.restoreState()
Ejemplo n.º 60
0
    def myFirstPage(self, canvas, doc):

        canvas.saveState()

        canvas.setFont('Times-Bold', 16)

        canvas.drawCentredString(self.PAGE_WIDTH / 2.0, self.PAGE_HEIGHT - 108,
                                 self.Title)

        canvas.setFont('Times-Roman', 9)

        canvas.drawString(inch, 0.75 * inch, "First Page / %s" % self.pageinfo)

        canvas.restoreState()