Example #1
0
    def myLaterPages(canvas, doc):

        PAGE_HEIGHT,PAGE_WIDTH = letter
        canvas.saveState()
        canvas.setPageSize(landscape(letter))

        canvas.drawImage(frunt_pag2, 0,0, PAGE_WIDTH,PAGE_HEIGHT )

        canvas.setStrokeColorRGB(0,1,1,alpha=0.1)

        ficha_no = doc.page-1
        #canvas.setStrokeColorRGB(0.7,0.7,0.7)
        canvas.setFillColorRGB(0,0,0)

        SHOW_GRID = False

        if SHOW_GRID:
            n = 5
            s = 200
            canvas.setFillColorRGB(0,0,1)
            canvas.setFont('Helvetica',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)) )

            # for i in range(s):
            #     x= i*n
            #     y=x
            #     canvas.drawString(x,0,"%s" % (x)) #horizontal
            #     canvas.drawString(0,y+1,"%s" % (x)) # vertical
            #     canvas.drawString(x,600,"%s" % (x)) #horizontal
            #     canvas.drawString(990,y,"%s" % (x)) # vertical
            #
            #     canvas.setStrokeColorRGB(0,0,1,alpha=0.7)
            #     canvas.setFont('Helvetica',1)
            #     for i in range(610):
            #         #canvas.rect(35,i*2, width=0.5, height=0.5, stroke=1)
            #         canvas.drawString(35,i,"%s -" % (i,) )

        canvas.setFont('Helvetica',7)
        LINE_1 = 508

        #fecha_elaboracion = doc.fecha_elaboracion
        #if not fecha_elaboracion:
        #    fecha_elaboracion = datetime.today()

        canvas.drawCentredString(137,LINE_1,str(fecha_elaboracion.year))
        canvas.drawCentredString(162,LINE_1,str(fecha_elaboracion.month))
        canvas.drawCentredString(180,LINE_1,str(fecha_elaboracion.day))

        canvas.drawCentredString(290,LINE_1,"VALLE DEL CAUCA")

        canvas.drawCentredString(740,LINE_1,"Ficha No. %s" % (int(ficha_no)+int(no_ficha_inicial)-1))

        canvas.setFont('Helvetica',5)
        canvas.drawString(75,115, "Elaboro: %s" % elaboro)
        canvas.drawString(215,115, "Reviso: %s" % reviso)

        canvas.restoreState()
Example #2
0
    def segunda_hoja_layout(self, canvas, doc):
        canvas.saveState()
        canvas.setPageSize(self.pagesize)

        logo = 'static/fondo2.jpg'
        canvas.drawImage(logo,
                         0 * cm,
                         0 * cm,
                         width=(8.5 * cm),
                         height=(5.28 * cm))

        firma = str(self.licencia.autoridad.firma_autoridad)
        canvas.drawImage(firma,
                         52 * mm,
                         0.7 * cm,
                         width=(2.6 * cm),
                         height=(1 * cm))

        size = 65.
        qr_code = qr.QrCodeWidget(self.licencia.persona.dni)
        bounds = qr_code.getBounds()
        width = bounds[2] - bounds[0]
        height = bounds[3] - bounds[1]
        d = Drawing(size,
                    size,
                    transform=[size / width, 0, 0, size / height, 0, 0])
        d.add(qr_code)
        renderPDF.draw(d, canvas, 54 * mm, 22 * mm)

        canvas.restoreState()
Example #3
0
    def myFirstPage(canvas, doc):
        PAGE_HEIGHT,PAGE_WIDTH = letter
        canvas.saveState()
        canvas.setPageSize(landscape(letter))
        canvas.setFont('Helvetica',20)
        canvas.drawCentredString(380,340,"FICHAS DE PRIORIZACION PROGRAMA COLOMBIA MAYOR")
        canvas.drawCentredString(380,320,"TOTAL CEDULAS:" + str(len(doc.rows)))

        canvas.restoreState()
Example #4
0
    def primera_hoja_layout(self, canvas, doc):
        canvas.saveState()
        canvas.setPageSize(self.pagesize)

        logo = 'static/fondo1.jpg'
        canvas.drawImage(logo,
                         0 * cm,
                         0 * cm,
                         width=(8.5 * cm),
                         height=(5.28 * cm))

        foto = str(self.licencia.persona.foto)
        canvas.drawImage(foto,
                         3 * mm,
                         1.3 * cm,
                         width=(2 * cm),
                         height=(2.5 * cm))

        foto = str(self.licencia.persona.firma)
        canvas.drawImage(foto,
                         51 * mm,
                         2.5 * cm,
                         width=(2.6 * cm),
                         height=(1 * cm))

        categoria = Paragraph(u'Categoría', negrita_custom(8.5, TA_LEFT))
        w, h = categoria.wrap(doc.width, doc.topMargin)
        categoria.drawOn(canvas, 52 * mm, 16.9 * mm)

        categoria = Paragraph(self.licencia.clase, normal_custom(8.5, TA_LEFT))
        w, h = categoria.wrap(doc.width, doc.topMargin)
        categoria.drawOn(canvas, 56 * mm, 12.5 * mm)

        categoria = Paragraph(self.licencia.categoria,
                              normal_custom(8.5, TA_LEFT))
        w, h = categoria.wrap(doc.width, doc.topMargin)
        categoria.drawOn(canvas, 53 * mm, 12.5 * mm)

        categoria = Paragraph(u'F. Revalidación', negrita_custom(8.5, TA_LEFT))
        w, h = categoria.wrap(doc.width, doc.topMargin)
        categoria.drawOn(canvas, 52 * mm, 8.2 * mm)

        categoria = Paragraph(
            self.licencia.fecha_revalidacion.strftime('%d/%m/%Y'),
            normal_custom(8.5, TA_LEFT))
        w, h = categoria.wrap(doc.width, doc.topMargin)
        categoria.drawOn(canvas, 53 * mm, 4 * mm)

        barcode = code93.Standard93(self.licencia.persona.dni,
                                    barWidth=0.55,
                                    barHeight=7.5 * mm,
                                    stop=1)
        w, h = barcode.wrap(doc.width, doc.topMargin)
        barcode.drawOn(canvas, -4 * mm, 6 * mm)

        canvas.restoreState()
Example #5
0
 def create_mug_pdf(image_name):
 
     from reportlab.pdfgen import canvas
     from reportlab.lib.units import inch
     
     canvas = canvas.Canvas('mug.pdf')
     canvas.setPageSize((8.58*inch, 3.7*inch))
     canvas.drawImage(image_name, 0.1*inch, 0.1*inch, 5.9*inch, 3.9*inch)
     canvas.showPage()
     canvas.save()
Example #6
0
 def create_backpdf(image_name):
 
     from reportlab.pdfgen import canvas
     from reportlab.lib.units import inch
     
     canvas = canvas.Canvas('PC_back.pdf')
     canvas.setPageSize((6*inch, 4*inch))
     canvas.drawImage(image_name, 0.1*inch, 0.1*inch, 5.9*inch, 3.9*inch)
     canvas.showPage()
     canvas.save()
Example #7
0
 def convert_pdf(image_name, width, height):
 
     from reportlab.pdfgen import canvas
     from reportlab.lib.units import inch
     
     canvas = canvas.Canvas('output.pdf')
     canvas.setPageSize((width*inch, height*inch))
     canvas.drawImage(image_name, 0.1*inch, 0.1*inch, (width-0.1)*inch, (height-0.1)*inch)
     canvas.showPage()
     canvas.save()
Example #8
0
def addPage(canvas, page, strokes):
    canvas.setLineCap(1)
    if page['height'] > page['width']:
        PAGE = (A4[0], A4[1])
    else:
        PAGE = (A4[1], A4[0])

    canvas.setPageSize(PAGE)
    S = PAGE[0] / page['width']

    for s in strokes:
        dots = s['dots']
        x0, y0, p0, dt0 = dots[0]

        for x, y, p, dt in dots[1:]:
            # the factor 1.5 visually matches the thickness in neonote app
            canvas.setLineWidth((s['thickness'] + 1.5) * p)
            col = s['color']
            canvas.setStrokeColorRGB(col[1] / 255, col[2] / 255, col[3] / 255)
            canvas.line(S * x0, S * y0, S * x, S * y)
            x0, y0, p0 = x, y, p

    canvas.showPage()
Example #9
0
  def create_frontpdf(toaddress_full,fromaddress_full = from_add):
#  (to_name, to_street_address, to_city, to_state, to_zip_code, from_name, from_street_address, from_city, from_state, from_zip_code):
# 
#
#  tempaddr1 = {
#            'name': 'Siddharth Saha',
#            'address_line': '220 William T Morrissey, Sunset Town',
#            'address_city': 'Boston',
#            'address_state': 'MA',
#            'address_country': 'US',
#            'address_zip': '02125'
#        }

      to_name = toaddress_full["name"]
      to_street_address = toaddress_full["address_line1"]
      to_city = toaddress_full["address_city"]
      to_state = toaddress_full["address_state"]
      to_zip_code = toaddress_full["address_zip"]
  
      from_name = fromaddress_full["name"]
      from_street_address = fromaddress_full["address_line1"]
      from_city = fromaddress_full["address_city"]
      from_state = fromaddress_full["address_state"]
      from_zip_code = fromaddress_full["address_zip"]
      
      from reportlab.pdfgen import canvas
      from reportlab.lib.units import inch
      from reportlab.lib.colors import black, white
  
      #CREATE THE FRONT SIDE
      canvas = canvas.Canvas("PC_front.pdf")
      canvas.setLineWidth(.3)
      canvas.setFont('Helvetica', 10)
      canvas.setPageSize((6*inch, 4*inch))
  
      #Border and Stamp
      canvas.setFillColor(white)
      canvas.rect(0.1*inch, 0.1*inch, 5.8*inch, 3.8*inch, stroke=1, fill=1)
      #canvas.rect(4.8*inch, 2.8*inch, 0.85*inch, 0.85*inch, stroke=1, fill=1)
  
      #Center Line
      canvas.line(3*inch, 0.5*inch, 3*inch, 3.5*inch)
  
      #To Address Lines (5 nos)
      
      canvas.setFillColor(black)
      canvas.drawString(3.4*inch, 3.4*inch,'To,')
      canvas.drawString(3.5*inch, 3.2*inch,to_name)
      canvas.drawString(3.5*inch, 3.0*inch,to_street_address)
      canvas.drawString(3.5*inch, 2.8*inch,to_city)
      canvas.drawString(3.5*inch, 2.6*inch,to_state)
      canvas.drawString(3.5*inch, 2.4*inch,to_zip_code)
  
      #From Address Lines (5 nos)
      
      canvas.setFillColor(black)
      canvas.drawString(3.4*inch, 2.0*inch,'From,')
      canvas.drawString(3.5*inch, 1.8*inch,from_name)
      canvas.drawString(3.5*inch, 1.6*inch,from_street_address)
      canvas.drawString(3.5*inch, 1.4*inch,from_city)
      canvas.drawString(3.5*inch, 1.2*inch,from_state)
      canvas.drawString(3.5*inch, 1.0*inch,from_zip_code)
  
      canvas.setFont('Helvetica', 18)
      canvas.drawString(0.5*inch, 2.5*inch,'Many Many Happy ')
      canvas.drawString(0.5*inch, 2.0*inch,'Returns of the Day')
      
  
      canvas.save()
Example #10
0
    def __init__(self,fi,title='This is the title',logo=None,site='',auth='',docid='',worklist=''):
        # site and auth
        self.site = site
        self.auth = auth
        self.docid = docid
        # get document
        self.doc = BaseDocTemplate(fi,
                      rightMargin=rightMargin,
                      leftMargin=leftMargin,
                      topMargin=topMargin,
                      bottomMargin=bottomMargin,
                      leftPadding = 0,
                      rightPadding = 0,
                      topPadding = 0,
                      bottomPadding = 0,
                      showBoundary=0)

        # style sheets
        self.styles = getSampleStyleSheet()
        self.styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
        self.styles.add(ParagraphStyle(name='Warning', backColor = '#FFFF00', borderColor = "#000000"))
        self.styles.add(ParagraphStyle(name='tiny', fontSize=4, leading=4, alignment=TA_CENTER))
        self.styles.add(ParagraphStyle(name='small', fontSize=6, leading=6))
        self.styles.add(ParagraphStyle(name='normal', fontSize=8, leading=6))
        self.styles.add(ParagraphStyle(name='big', fontSize=10, leading=6))
        self.styles.add(ParagraphStyle(name='huge', fontSize=12, leading=6))

        # add Page templates
        frame1 = Frame(self.doc.leftMargin, self.doc.bottomMargin,
            self.doc.width, self.doc.height)
        frame2 = Frame(self.doc.leftMargin, self.doc.bottomMargin,
            self.doc.height, self.doc.width)
        ptemplate = PageTemplate(id='portrait',frames =[frame1], onPage=lambda canvas, doc: canvas.setPageSize(A4))
        ltemplate = PageTemplate(id='landscape',frames =[frame2], onPage=lambda canvas, doc: canvas.setPageSize(landscape(A4)))
        self.doc.addPageTemplates([ptemplate, ltemplate])

        # flowable elements
        self.elements = []
        # Header
        logo = Image(os.path.join(imageDir,logo),width=1.32*inch,height=0.7*inch) if logo else Paragraph('LOGO', self.styles["Heading1"])
        titl = Paragraph('%s' % title, self.styles["Heading2"])
        date = Paragraph('<font size=10>Generated on %s</font>' % time.ctime(), self.styles["Normal"])
        self.elements.append(Table([[logo,titl],['',date]],
            colWidths=[1.5*inch,4.5*inch],
            style=[ ('SPAN',(0,0),(0,1)), ('VALIGN',(0,0),(-1,-1),'BOTTOM'),
                ('VALIGN',(1,1),(-1,-1),'TOP'), ('ALIGN',(1,0),(-1,-1),'LEFT') ]))
        self.elements.append(Spacer(1, 12))
        # header fields
        TABLE_STYLE = TableStyle([
            ('ALIGN',(0,0),(-1,-1),'RIGHT'),
            ('VALIGN',(0,0),(-1,-1),'MIDDLE'),
            ('FONTSIZE',(0,1),(-1,-1),8),
            ('INNERGRID', (0,0), (1,0), 0.25, colors.black),
            ('BOX', (0,0), (1,0), 1, colors.black),
            ('BACKGROUND', (0,0), (0,0), colors.cyan),
            ('INNERGRID', (3,0), (4,0), 0.25, colors.black),
            ('BOX', (3,0), (4,0), 1, colors.black),
            ('BACKGROUND', (3,0), (3,0), colors.cyan),
            ('INNERGRID', (6,0), (7,0), 0.25, colors.black),
            ('BOX', (6,0), (7,0), 1, colors.black),
            ('BACKGROUND', (6,0), (6,0), colors.cyan)
            ])
        self.elements.append(Spacer(1, 2))
        data = [[ 'Date','','','Checker','','','Worklist',worklist]]
        t = Table(data, \
            colWidths=[2.3*cm, 2.3*cm, 0.85*cm, 2.3*cm, 2.3*cm, 0.85*cm, 2.3*cm, 2.3*cm], rowHeights=0.6*cm)
        t.setStyle(TABLE_STYLE)
        self.elements.append(t)
        self.elements.append(Spacer(1, 12))
Example #11
0
            def contenido(canvas, datos):
                from reportlab.lib.colors import darkblue, black
                canvas.setFillColor(darkblue)
                canvas.setFillColor(black)
                canvas.setStrokeColor(black)
                canvas.setPageSize(landscape(A4))

                for dato in datos:
                    canvas.setFont("Helvetica", 12)
                    canvas.drawString(30, 570, "Fecha de inicio:")
                    canvas.setFont("Helvetica", 13)
                    canvas.drawString(
                        140, 570, dato.fecha_de_inicio.strftime('%d/%m/%Y'))

                    canvas.setFont("Helvetica", 12)
                    canvas.drawString(30, 550, "Fecha de entrega:")
                    canvas.setFont("Helvetica", 13)
                    canvas.drawString(
                        140, 550, dato.fecha_de_entrega.strftime('%d/%m/%Y'))

                    canvas.setFont("Helvetica", 12)
                    canvas.drawString(30, 530, "Maquina:")
                    canvas.setFont("Helvetica", 13)
                    canvas.drawString(140, 530, str(dato.maquina))

                    canvas.setFont("Helvetica", 13)
                    canvas.drawString(480, 530, "Programado")

                    canvas.setFont("Helvetica", 13)
                    canvas.drawString(570, 530, "Realizado")

                    # LINEA HORIZONTAL QUE SEPARA LA CABECERA DEL RESTO
                    canvas.line(20, 520, 820, 520)

                    canvas.setFont("Helvetica-Bold", 13)
                    canvas.drawString(40, 505, "O.T")
                    canvas.drawString(260, 505, "Cliente")
                    canvas.drawString(375, 505, "Tiradas")
                    canvas.drawString(430, 505, "Pasadas")
                    canvas.drawString(490, 505, "Inicio")
                    canvas.drawString(530, 505, "Fin")
                    canvas.drawString(570, 505, "Inicio")
                    canvas.drawString(610, 505, "Fin")
                    canvas.drawString(648, 505, "Tirada Fin")
                    canvas.drawString(728, 505, "Responsable")
                    canvas.line(20, 500, 820, 500)

                    row = 500
                    canvas.setFont("Helvetica", 11)
                    programaciones = DetalleProgramacion.objects.filter(
                        programacion=dato)
                    for programacion in programaciones:
                        row -= 20
                        canvas.drawString(
                            40, row,
                            force_text(programacion.detalle_proceso.proceso.
                                       orden_de_trabajo)[:38])
                        canvas.line(255, row - 5, 255, row + 40)
                        canvas.drawString(
                            260, row,
                            force_text(
                                programacion.detalle_proceso.proceso.
                                orden_de_trabajo.cliente.razon_social[:15]))
                        canvas.line(373, row - 5, 373, row + 40)
                        canvas.drawString(
                            370, row,
                            separar(int(round(
                                programacion.pliegos))).rjust(15))
                        canvas.line(430, row - 5, 430, row + 40)
                        canvas.drawString(
                            430, row,
                            separar(
                                int(
                                    round(programacion.detalle_proceso.
                                          pasadas_por_pliego))).rjust(15))
                        canvas.line(485, row - 5, 485, row + 40)
                        canvas.drawString(
                            490, row,
                            programacion.hora_de_inicio.strftime('%H:%M'))
                        canvas.line(525, row - 5, 525, row + 40)
                        canvas.drawString(
                            530, row,
                            programacion.hora_de_finalizacion.strftime(
                                '%H:%M'))
                        canvas.line(565, row - 5, 565, row + 40)
                        canvas.line(605, row - 5, 605, row + 40)
                        canvas.line(645, row - 5, 645, row + 40)
                        canvas.line(720, row - 5, 720, row + 40)
                        canvas.line(20, row - 5, 820, row - 5)

                    canvas.line(20, 520, 20, row - 5)
                    canvas.line(820, 520, 820, row - 5)

                    row -= 30
                    canvas.setFont("Helvetica", 10)
                    canvas.drawString(30, 20,
                                      "Fecha: %s" % time.strftime("%Y/%m/%d"))
                    canvas.drawString(200, 20,
                                      "Hora: %s" % time.strftime("%X"))
                    canvas.showPage()
Example #12
0
def fill_page_with_image(path, canvas):
    """
    Given the path to an image and a reportlab canvas, fill the current page
    with the image.

    This function takes into consideration EXIF orientation information (making
    it compatible with photos taken from iOS devices).

    This function makes use of ``canvas.setPageRotation()`` and
    ``canvas.setPageSize()`` which will affect subsequent pages, so be sure to
    reset them to appropriate values after calling this function.

    :param   path: filesystem path to an image
    :param canvas: ``reportlab.canvas.Canvas`` object
    """
    from PIL import Image

    page_width, page_height = canvas._pagesize

    image = Image.open(path)
    image_width, image_height = image.size
    if hasattr(image, '_getexif'):
        orientation = (image._getexif() or {}).get(274, 1)  # 274 = Orientation
    else:
        orientation = 1

    # These are the possible values for the Orientation EXIF attribute:
    ORIENTATIONS = {
        1: "Horizontal (normal)",
        2: "Mirrored horizontal",
        3: "Rotated 180",
        4: "Mirrored vertical",
        5: "Mirrored horizontal then rotated 90 CCW",
        6: "Rotated 90 CW",
        7: "Mirrored horizontal then rotated 90 CW",
        8: "Rotated 90 CCW",
    }
    draw_width, draw_height = page_width, page_height
    if orientation == 1:
        canvas.setPageRotation(0)
    elif orientation == 3:
        canvas.setPageRotation(180)
    elif orientation == 6:
        image_width, image_height = image_height, image_width
        draw_width, draw_height = page_height, page_width
        canvas.setPageRotation(90)
    elif orientation == 8:
        image_width, image_height = image_height, image_width
        draw_width, draw_height = page_height, page_width
        canvas.setPageRotation(270)
    else:
        raise ValueError("Unsupported image orientation '%s'."
                         % ORIENTATIONS[orientation])

    if image_width > image_height:
        page_width, page_height = page_height, page_width  # flip width/height
        draw_width, draw_height = draw_height, draw_width
        canvas.setPageSize((page_width, page_height))

    # Ameriks custom implementation to position in the middle image.
    # TODO: Testing with rotated image
    draw_width = page_width
    draw_height = (page_width * image_height) / image_width

    if draw_height < page_height:

        draw_height = page_height
        draw_width = (page_height * image_width) / image_height

    x = 0
    if draw_width > page_width:
        x = (page_width - draw_width) / 2.0
    y = 0
    if draw_height > page_height:
        y = (page_height - draw_height) / 2.0

    canvas.drawImage(path, x, y, width=draw_width, height=draw_height,
                     preserveAspectRatio=True)
 def set_size(self, canvas):
     canvas.setPageSize((self.width * 2, self.height))
def makeBill(items, discount, type):

    if type != 2:
        discount = 0

    from reportlab.lib.pagesizes import letter
    from reportlab.pdfgen import canvas
    import datetime

    ##################### Date And Time For Bill #########################
    now = datetime.datetime.today()
    CurrentDate = str(now.strftime('%Y-%m-%d'))
    CurrentTime = str(now.strftime("%I:%M:%S %p"))
    ##### Read from text file the order number and the bill name #########
    txtFile = open("myfile.txt", 'r')
    orderNumber = txtFile.read()
    billName = str("./Bills/" + orderNumber + ".pdf")
    # orderNumber = int(orderNumber)
    ######################################################################
    canvas = canvas.Canvas(billName, pagesize=letter)
    canvas.setPageSize((58, 270))
    canvas.setLineWidth(.3)
    canvas.setFont('Helvetica', 6)
    # canvas.drawString(1.9,107,'卐')
    canvas.line(0, 262, 58, 262)
    canvas.line(0, 263, 58, 263)
    canvas.line(0, 264, 58, 264)
    canvas.line(0, 265, 58, 265)
    ########################## Address And Details ##############################
    canvas.drawString(1.9, 254, 'Chhabra Restaurant')
    canvas.setFont('Helvetica', 2.5)
    canvas.drawString(9.5, 250, ' Adjoining S.B.I. Grain Market Branch ')
    canvas.setFont('Helvetica', 2)
    canvas.drawString(11.9, 247.7, 'Near Durga Mandir Gate , Rajpura Town')
    canvas.setFont('Helvetica', 2.5)
    canvas.drawString(12.4, 245.3, 'Phone Number : 01762-225854')
    canvas.drawString(5, 240, 'Date : ' + CurrentDate)
    canvas.drawString(33, 240, 'Time : ' + CurrentTime)
    canvas.setFont('Helvetica', 3)
    canvas.drawString(20, 235, 'ORDER NO.: ' + orderNumber)
    canvas.line(0, 233, 58, 232)  # 3 ka difference

    ##### Write to text file next order number #########
    a = int(orderNumber) + 1
    a = str(a)
    txtFile = open("myfile.txt", 'w')
    orderNumber = txtFile.write(a)

    ################################################################################
    canvas.setFont('Helvetica', 3.5)  # 4 ka difference
    canvas.drawString(4, 228, 'Item')
    canvas.drawString(17, 228, 'Units')
    canvas.drawString(30, 228, 'Price')
    canvas.drawString(42, 228, 'Subtotal')
    canvas.line(0, 226, 58, 226)
    ######################## Now Dynamic Billing Starts ##############################

    y_cord = 221

    canvas.setFont('Helvetica', 3)

    subtotal = 0

    for item in items:
        canvas.drawString(4, y_cord, item.name[0:8])
        canvas.drawString(20, y_cord, item.units)
        canvas.drawString(30, y_cord, str(item.price))
        canvas.drawString(42, y_cord, str(item.total))
        subtotal = subtotal + float(item.total)
        y_cord = y_cord - 4

    ###################################################################################

    canvas.line(24, y_cord - 5, 55, y_cord - 5)
    y_cord = y_cord - 10
    canvas.drawString(26, y_cord, 'Sub Total :')
    canvas.drawString(43, y_cord, str(subtotal))

    if type == 2:
        canvas.drawString(23, y_cord - 4, '-   Discount  :')
        canvas.drawString(43, y_cord - 4, str(discount))
        y_cord = y_cord - 4
        subtotal = float(subtotal) - float(discount)

    if subtotal % 1 >= 0.5:
        subtotal = subtotal - (subtotal % 1) + 1
    else:
        subtotal = subtotal - (subtotal % 1)
    canvas.drawString(23, y_cord - 4, 'Round OFF :')
    canvas.drawString(43, y_cord - 4, str(subtotal))

    y_cord = y_cord - 8
    canvas.line(0, y_cord, 58, y_cord)
    canvas.setFont('Helvetica', 1.5)
    y_cord = y_cord - 5
    canvas.drawString(5, y_cord, 'E. & O.E.')
    canvas.setFont('Helvetica', 5)
    canvas.drawString(26, y_cord - 1, 'Total')
    canvas.drawString(40, y_cord - 1, str(subtotal))
    y_cord = y_cord - 4
    canvas.line(0, y_cord, 58, y_cord)
    canvas.setFont('Helvetica', 2)
    y_cord = y_cord - 5
    canvas.drawString(20, y_cord, 'Thanks Visit Again!')
    y_cord = y_cord - 4
    canvas.drawString(21, y_cord, 'Have A Nice Day!')
    y_cord = y_cord - 4
    canvas.line(0, y_cord, 58, y_cord)
    canvas.line(0, y_cord - 1, 58, y_cord - 1)
    canvas.line(0, y_cord - 1, 58, y_cord - 1)
    canvas.line(0, y_cord - 1, 58, y_cord - 1)
    canvas.save()
Example #15
0
 def set_size(self, canvas):
     canvas.setPageSize((self.WIDTH * 2, self.HEIGHT))
Example #16
0
def fill_page_with_image(path, canvas):
    """
    Given the path to an image and a reportlab canvas, fill the current page
    with the image.

    This function takes into consideration EXIF orientation information (making
    it compatible with photos taken from iOS devices).

    This function makes use of ``canvas.setPageRotation()`` and
    ``canvas.setPageSize()`` which will affect subsequent pages, so be sure to
    reset them to appropriate values after calling this function.

    :param   path: filesystem path to an image
    :param canvas: ``reportlab.canvas.Canvas`` object
    """
    from PIL import Image

    page_width, page_height = canvas._pagesize

    image = Image.open(path)
    image_width, image_height = image.size
    if hasattr(image, '_getexif'):
        orientation = (image._getexif() or {}).get(274, 1)  # 274 = Orientation
    else:
        orientation = 1

    # These are the possible values for the Orientation EXIF attribute:
    ORIENTATIONS = {
        1: "Horizontal (normal)",
        2: "Mirrored horizontal",
        3: "Rotated 180",
        4: "Mirrored vertical",
        5: "Mirrored horizontal then rotated 90 CCW",
        6: "Rotated 90 CW",
        7: "Mirrored horizontal then rotated 90 CW",
        8: "Rotated 90 CCW",
    }
    draw_width, draw_height = page_width, page_height
    if orientation == 1:
        canvas.setPageRotation(0)
    elif orientation == 3:
        canvas.setPageRotation(180)
    elif orientation == 6:
        image_width, image_height = image_height, image_width
        draw_width, draw_height = page_height, page_width
        canvas.setPageRotation(90)
    elif orientation == 8:
        image_width, image_height = image_height, image_width
        draw_width, draw_height = page_height, page_width
        canvas.setPageRotation(270)
    else:
        raise ValueError("Unsupported image orientation '%s'."
                         % ORIENTATIONS[orientation])

    if image_width > image_height:
        page_width, page_height = page_height, page_width  # flip width/height
        draw_width, draw_height = draw_height, draw_width
        canvas.setPageSize((page_width, page_height))

    # Ameriks custom implementation to position in the middle image.
    # TODO: Testing with rotated image
    draw_width = page_width
    draw_height = (page_width * image_height) / image_width

    if draw_height < page_height:

        draw_height = page_height
        draw_width = (page_height * image_width) / image_height

    x = 0
    if draw_width > page_width:
        x = (page_width - draw_width) / 2.0
    y = 0
    if draw_height > page_height:
        y = (page_height - draw_height) / 2.0

    canvas.drawImage(path, x, y, width=draw_width, height=draw_height,
                     preserveAspectRatio=True)
Example #17
0
h = lWidth
w = lHeight


startdate = datetime.datetime(2018, 5,7)
#days to process#
cdays = 350

pages = int(cdays/2)

#  timedelta(days=1) + startdate = next day, etc etc



canvas = canvas.Canvas("output2.pdf", pagesize=letter)
canvas.setPageSize((lHeight, lWidth))

side="A"
for leday in range(0,pages):
    canvas.setLineWidth(.3)
    canvas.setFont('Helvetica', 8)
    pad = 15
    bindpad = 45
    
    if side == 'A':
    
        day = startdate + timedelta(days=leday)
        day2 = startdate + timedelta(days=pages) + timedelta(days=leday)
        side = 'B'
        
    else:
Example #18
0
    def myLaterPages(canvas, doc):

        PAGE_HEIGHT,PAGE_WIDTH = letter
        canvas.saveState()
        canvas.setPageSize(landscape(letter))

        canvas.drawImage(frunt_pag2, 0,0, PAGE_WIDTH,PAGE_HEIGHT )

        canvas.setStrokeColorRGB(0,1,1,alpha=0.1)

        ficha_no = doc.page-1
        #canvas.setStrokeColorRGB(0.7,0.7,0.7)
        canvas.setFillColorRGB(0,0,0)

        SHOW_GRID = False

        if SHOW_GRID:
            n = 5
            s = 200
            canvas.setFillColorRGB(0,0,1)
            canvas.setFont('Helvetica',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)) )

            # for i in range(s):
            #     x= i*n
            #     y=x
            #     canvas.drawString(x,0,"%s" % (x)) #horizontal
            #     canvas.drawString(0,y+1,"%s" % (x)) # vertical
            #     canvas.drawString(x,600,"%s" % (x)) #horizontal
            #     canvas.drawString(990,y,"%s" % (x)) # vertical
            #
            #     canvas.setStrokeColorRGB(0,0,1,alpha=0.7)
            #     canvas.setFont('Helvetica',1)
            #     for i in range(610):
            #         #canvas.rect(35,i*2, width=0.5, height=0.5, stroke=1)
            #         canvas.drawString(35,i,"%s -" % (i,) )

        canvas.setFont('Helvetica',7)
        LINE_1 = 508

        #fecha_elaboracion = doc.fecha_elaboracion
        #if not fecha_elaboracion:
        #    fecha_elaboracion = datetime.today()

        canvas.drawCentredString(137,LINE_1,str(fecha_elaboracion.year))
        canvas.drawCentredString(162,LINE_1,str(fecha_elaboracion.month))
        canvas.drawCentredString(180,LINE_1,str(fecha_elaboracion.day))

        canvas.drawCentredString(290,LINE_1,"VALLE DEL CAUCA")
        canvas.drawCentredString(478,LINE_1,"SANTIAGO DE CALI")

        canvas.drawCentredString(581,LINE_1,"7")
        canvas.drawCentredString(598,LINE_1,"6")
        canvas.drawCentredString(620,LINE_1,"0")
        canvas.drawCentredString(645,LINE_1,"0")
        canvas.drawCentredString(673,LINE_1,"1")

        canvas.drawCentredString(740,LINE_1,"Ficha No. %s" % (int(ficha_no)+int(no_ficha_inicial)-1))

        canvas.drawCentredString(177,142,"ESAUD URRUTIA NOEL")
        canvas.drawCentredString(177,132,"Secretario de Desarrollo Territorial y Bienestar Social")
        canvas.drawCentredString(177,123,"71.993.571 de Caceres")

        canvas.setFont('Helvetica',5)
        canvas.drawString(75,115, "Elaboro: %s" % elaboro)
        canvas.drawString(215,115, "Reviso: %s" % reviso)

        LINES = [401,390, 379, 368,358, 347, 336, 325, 314, 303, 293, 282, 272, 261, 250, 238, 228, 218, 207, 197 ]
        LINE_1_L = 0
        i=0
        ini = (ficha_no*20)-20
        fin = (ficha_no*20)

        for row in doc.rows[ini:fin]: #[total_pages:]:
            line = LINES[i]
            canvas.drawCentredString(53,line, row["fecha_inscripcion"])
            canvas.drawCentredString(98,line,row["cedula"])
            canvas.drawCentredString(147,line,row["apellido1"])
            canvas.drawCentredString(195,line,row["apellido2"])
            canvas.drawCentredString(244,line,row["nombre1"])
            canvas.drawCentredString(292,line,row["nombre2"])
            canvas.drawCentredString(381,line,row["direccion"])
            canvas.drawCentredString(472,line,row["telefono"])
            canvas.drawCentredString(512,line,row["fecha_nac_ano"])
            canvas.drawCentredString(544,line,row["fecha_nac_mes"])
            canvas.drawCentredString(576,line,row["fecha_nac_dia"])
            canvas.drawCentredString(598,line,row["genero"])
            canvas.drawCentredString(614,line,row["p_sisben_1"])
            canvas.drawCentredString(627,line,row["p_sisben_2"])
            canvas.drawCentredString(638,line,row["p_sisben_3"])
            canvas.drawCentredString(653,line,row["p_sisben_4"])
            canvas.drawCentredString(673,line,row["ubicacion"])
            canvas.drawCentredString(700,line,row["tiempo_residencia"])
            canvas.drawCentredString(722,line,row["condicion_am"])
            canvas.drawCentredString(738,line,row["con_personas_cargo"])
            canvas.drawCentredString(754,line,row["discapacitado"])
            canvas.drawCentredString(768,line,row["indigena"])
            i=i+1

        canvas.restoreState()