Ejemplo n.º 1
0
    def draw_qrcode(self, value, x, y, size=40, halign=None, valign=None):
        """
            Helper function to draw a QR code

            @param value: the string to encode
            @param x: drawing position
            @param y: drawing position
            @param size: the size (edge length) of the QR code
            @param halign: horizontal alignment ("left"|"center"|"right"), default left
            @param valign: vertical alignment ("top"|"middle"|"bottom"), default bottom
        """

        qr_code = qr.QrCodeWidget(value)

        bounds = qr_code.getBounds()
        w = bounds[2] - bounds[0]
        h = bounds[3] - bounds[1]

        transform = [float(size) / w, 0, 0, float(size) / h, 0, 0]
        d = Drawing(size, size, transform=transform)
        d.add(qr_code)

        hshift = vshift = 0
        if halign == "right":
            hshift = size
        elif halign == "center":
            hshift = float(size) / 2.0

        if valign == "top":
            vshift = size
        elif valign == "middle":
            vshift = float(size) / 2.0

        renderPDF.draw(d, self.canv, x - hshift, y - vshift)
Ejemplo n.º 2
0
def createBarCodes():
    """
    Create barcode examples and embed in a PDF
    """
    c = canvas.Canvas("barcodes.pdf", pagesize=A4)

    barcode_value = "1234567890"

    barcode39 = code39.Extended39(barcode_value)
    barcode39Std = code39.Standard39(barcode_value, barHeight=20, stop=1)

    # code93 also has an Extended and MultiWidth version
    barcode93 = code93.Standard93(barcode_value)

    barcode128 = code128.Code128(barcode_value)
    # the multiwidth barcode appears to be broken
    #barcode128Multi = code128.MultiWidthBarcode(barcode_value)

    barcode_usps = usps.POSTNET("50158-9999")

    codes = [barcode39, barcode39Std, barcode93, barcode128, barcode_usps]

    x = 1 * mm
    y = 285 * mm
    x1 = 6.4 * mm

    for code in codes:
        code.drawOn(c, x, y)
        y = y - 15 * mm

    # draw the eanbc8 code
    barcode_eanbc8 = eanbc.Ean8BarcodeWidget(barcode_value)
    bounds = barcode_eanbc8.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(50, 10)
    d.add(barcode_eanbc8)
    renderPDF.draw(d, c, 15, 555)

    # draw the eanbc13 code
    barcode_eanbc13 = eanbc.Ean13BarcodeWidget(barcode_value)
    bounds = barcode_eanbc13.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(50, 10)
    d.add(barcode_eanbc13)
    renderPDF.draw(d, c, 15, 465)

    # draw a QR code
    qr_code = qr.QrCodeWidget(
        'https://stackoverflow.com/questions/10147455/how-to-send-an-email-with-gmail-as-provider-using-python'
    )
    bounds = qr_code.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(45, 45, transform=[45. / width, 0, 0, 45. / height, 0, 0])
    d.add(qr_code)
    renderPDF.draw(d, c, 15, 405)

    c.save()
Ejemplo n.º 3
0
def draw_qr_sdaps_info(canvas, survey, page):
    # The page number is one based here already
    # The survey_id is a 32bit number, which means we need
    # 10 decimal digits to encode it, then we need to encode the
    # the page with at least 3 digits(just in case someone is insane enough
    # to have a questionnaire with more than 99 pages.
    # So use 10+4 digits

    value = "%010d%04d" % (survey.survey_id, page)

    y = survey.defs.paper_height - defs.corner_mark_bottom
    x = survey.defs.paper_width - defs.corner_mark_right

    qr_code = qr.QrCodeWidget(value, barLevel='H')
    bounds = qr_code.getBounds()

    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]

    # Squeeze into the space between corner mark and content
    size = defs.bottom_page_margin - defs.corner_mark_bottom

    code_y = y
    code_x = x - size

    d = Drawing(size * mm,
                size * mm,
                transform=[
                    float(size * mm) / width, 0, 0, -float(size * mm) / height,
                    0, 0
                ])
    d.add(qr_code)

    renderPDF.draw(d, canvas, code_x * mm, code_y * mm)
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
def draw_qr_global_id(canvas, survey):
    if survey.global_id is None:
        raise AssertionError

    # Only allow ascii
    value = survey.global_id.encode('ascii')

    y = survey.defs.paper_height - defs.corner_mark_bottom
    x = (survey.defs.paper_width - defs.corner_mark_right +
         defs.corner_mark_left) / 2

    qr_code = qr.QrCodeWidget(value, barLevel='H')
    bounds = qr_code.getBounds()

    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]

    # Squeeze into the space between corner mark and content
    size = defs.bottom_page_margin - defs.corner_mark_bottom

    code_y = y
    code_x = x - size / 2.0

    d = Drawing(size * mm,
                size * mm,
                transform=[
                    float(size * mm) / width, 0, 0, -float(size * mm) / height,
                    0, 0
                ])
    d.add(qr_code)

    renderPDF.draw(d, canvas, code_x * mm, code_y * mm)
Ejemplo n.º 6
0
    def later_pages(canvas, document):
        canvas.saveState()
        #вывести внизу QR-code (ФИО, (номера направлений))
        qr_code = qr.QrCodeWidget(qr_value)
        qr_code.barWidth = 70
        qr_code.barHeight = 70
        qr_code.qrVersion = 1
        bounds = qr_code.getBounds()
        width = bounds[2] - bounds[0]
        height = bounds[3] - bounds[1]
        d = Drawing()
        d.add(qr_code)
        renderPDF.draw(d, canvas, 90 * mm, 7)
        #вывести атрибуты для подписей
        canvas.setFont('PTAstraSerifReg', 10)
        canvas.drawString(40 * mm, 10 * mm, '____________________________')
        canvas.drawString(115 * mm, 10 * mm,
                          '/{}/____________________________'.format(npf))

        canvas.setFont('Symbola', 18)
        canvas.drawString(195 * mm, 10 * mm, '\u2713')

        canvas.setFont('PTAstraSerifReg', 8)
        canvas.drawString(50 * mm, 7 * mm, '(подпись сотрудника)')
        canvas.drawString(160 * mm, 7 * mm, '(подпись плательщика)')

        canvas.rotate(90)
        canvas.setFillColor(HexColor(0x4f4b4b))
        canvas.setFont('PTAstraSerifReg', 5.2)
        canvas.drawString(10 * mm, -12 * mm, '{}'.format(6 * left_size_str))
        canvas.restoreState()
Ejemplo n.º 7
0
def createBarCodes():
    """
    Create barcode examples and embed in a PDF
    """
    """ c = canvas.Canvas("barcodes.pdf", pagesize=QRCode) """

    doc = SimpleDocTemplate("complex_cell_values.pdf", pagesize=QRCode)

    elements = []

    styleSheet = getSampleStyleSheet()

    barcode_value = "1234567890"

    # draw a QR code
    qr_code = qr.QrCodeWidget(barcode_value)
    d = Drawing(20 * mm, 20 * mm)
    d.add(qr_code)

    data = [['d', 'd', 'd'], ['d', 'd', 'd']]

    # 3 cot*chieu rong hang, 3 dong * chieu dai 1 cot
    t = Table(data, 3 * [36.6 * mm], 2 * [17 * mm])

    t.setStyle(
        TableStyle([('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                    ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
                    ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black),
                    ('BOX', (0, 0), (-1, -1), 0.25, colors.black),
                    ('TOPPADDING', (0, 0), (-1, -1), 0 * mm),
                    ('BOTTOMPADDING', (0, 0), (-1, -1), 0 * mm)]))

    elements.append(t)
    # write the document to disk
    doc.build(elements)
Ejemplo n.º 8
0
def send_pdf1(bill_object):
    username = bill_object.user.username
    month = bill_object.month
    bill_unit = bill_object.billing_units
    bill_amount = bill_object.bill_amount
    billname = str(username) + str(month) + ".pdf"
    path = os.path.join(dir_path + "/static", billname)
    c = canvas.Canvas(path, pagesize=letter)

    #c= canvas.Canvas("Qrcodes1.pdf", pagesize=letter)

    c.setFontSize(size=20)
    c.drawString(20, 600, "Username:"******"Month:")
    c.drawString(250, 560, month)
    c.drawString(20, 520, "Billing_units:")
    c.drawString(250, 520, str(bill_unit))

    c.drawString(20, 480, "Billing Amount:")
    c.drawString(250, 480, str(bill_amount))

    qr_code = qr.QrCodeWidget(str(bill_object.id))
    bounds = qr_code.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(60, 60, transform=[60. / width, 0, 0, 60. / height, 0, 0])
    d.add(qr_code)
    renderPDF.draw(d, c, 500, 560)
    c.save()
    return billname
Ejemplo n.º 9
0
def generateQR(value, file):
    packet = io.BytesIO()
    can = canvas.Canvas(packet)

    qrcode = qr.QrCodeWidget(value)
    bounds = qrcode.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]

    d = Drawing(100, 100, transform=[300. / width, 0, 0, 300. / height, 0, 0])
    d.add(qrcode)
    renderPDF.draw(d, can, 390, 430)

    can.save()

    packet.seek(0)

    new_pdf = PdfFileReader(packet)
    pdf = PdfFileReader(open(file, 'rb'))

    page = pdf.getPage(0)
    page2 = new_pdf.getPage(0)

    page.mergePage(page2)

    return page
Ejemplo n.º 10
0
def createBarCodes(c, barcode_value):
    # 条码生成
    barcode128 = code128.Code128(barcode_value)
    barcode128.barWidth = 1.1
    barcode128.drawOn(c, -7.15, 15)
    # 字符添加
    c.setFont(
        'Helvetica-Bold',
        9,
    )
    c.drawString(35, 3, barcode_value)
    # 二维码生成
    qrstr = QR_Prefix + barcode_value
    qr_code = qr.QrCodeWidget(qrstr)
    bounds = qr_code.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(
        45,
        40,
        transform=[45. / (width - 15), 0, 0, 45. / (height - 15), 0, 0])
    d.add(qr_code)
    renderPDF.draw(d, c, 60, 33)
    # 添加图片
    c.drawImage('.\img\img.jpg', 12.85, 40)
Ejemplo n.º 11
0
def write_qr_code(delegate, layout):
    qr_code = qr.QrCodeWidget(
        "{} <{}>".format(delegate.name, delegate.email), barLevel="H"
    )
    bounds = qr_code.getBounds()
    qr_width = bounds[2] - bounds[0]
    qr_height = bounds[3] - bounds[1]
    qr_size = 200.0
    d = Drawing(
        qr_size,
        qr_size,
        transform=[qr_size / qr_width, 0, 0, qr_size / qr_height, 0, 0],
    )
    d.add(qr_code)
    renderPDF.draw(
        d,
        layout.canvas,
        (layout.section_width - qr_size) / 2.0,
        (layout.section_height - qr_size) / 2.0,
    )

    logo_width = 60
    logo_height = 60
    layout.canvas.drawImage(
        os.path.join(here, "img", "logo_in_qrcode.png"),
        (layout.section_width - logo_width) / 2.0,
        (layout.section_height - logo_height) / 2.0,
        width=logo_width,
        height=logo_height,
        mask="auto",
    )
Ejemplo n.º 12
0
def draw_qr_questionnaire_id(canvas, survey, id):
    # Only supports ascii for now (see also defs.py)
    value = unicode(id).encode('ascii')

    y = survey.defs.paper_height - defs.corner_mark_bottom
    x = defs.corner_mark_left

    qr_code = qr.QrCodeWidget(value, barLevel='H')
    bounds = qr_code.getBounds()

    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]

    # Squeeze into the space between corner mark and content
    size = defs.bottom_page_margin - defs.corner_mark_bottom

    code_y = y
    code_x = x

    d = Drawing(size * mm,
                size * mm,
                transform=[
                    float(size * mm) / width, 0, 0, -float(size * mm) / height,
                    0, 0
                ])
    d.add(qr_code)

    renderPDF.draw(d, canvas, code_x * mm, code_y * mm)
Ejemplo n.º 13
0
Archivo: cards.py Proyecto: vmx/pretalx
    def draw(self):
        self.canv.rect(0, 0, self.width, self.height)

        self.canv.rotate(90)
        self.canv.setFont("Helvetica", 16)
        self.canv.drawString(25 * mm, -12 * mm,
                             str(self.submission.submission_type.name))
        self.canv.rotate(-90)

        qr_code = qr.QrCodeWidget(
            self.submission.orga_urls.quick_schedule.full())
        bounds = qr_code.getBounds()
        width = bounds[2] - bounds[0]
        height = bounds[3] - bounds[1]
        d = Drawing(45, 45, transform=[45 / width, 0, 0, 45 / height, 0, 0])
        d.add(qr_code)
        renderPDF.draw(d, self.canv, 15, 10)

        p = Paragraph(self.submission.title, style=self.styles["Title"])
        w, h = p.wrapOn(self.canv, self.width - 30 * mm, 50 * mm)
        y = h + 10 * mm
        p.drawOn(self.canv, *self.coord(20 * mm, y))

        p = Paragraph(
            ", ".join([
                s.get_display_name() for s in self.submission.speakers.all()
            ]),
            style=self.styles["Speaker"],
        )
        w, h = p.wrapOn(self.canv, self.width - 30 * mm, 50 * mm)
        y += h + 2 * mm
        p.drawOn(self.canv, *self.coord(20 * mm, y))

        p = Paragraph(
            _('{} minutes, #{}, {}, {}').format(
                self.submission.get_duration(),
                self.submission.code,
                self.submission.content_locale,
                self.submission.state,
            ),
            style=self.styles["Meta"],
        )
        w, h = p.wrapOn(self.canv, self.width - 30 * mm, 50 * mm)
        y += h + 2 * mm
        p.drawOn(self.canv, *self.coord(20 * mm, y))

        if self.submission.abstract:
            p = Paragraph(ellipsize(self.submission.abstract, 140),
                          style=self.styles["Meta"])
            w, h = p.wrapOn(self.canv, self.width - 30 * mm, 50 * mm)
            y += h + 2 * mm
            p.drawOn(self.canv, *self.coord(20 * mm, y))

        if self.submission.notes:
            p = Paragraph(ellipsize(self.submission.notes, 140),
                          style=self.styles["Meta"])
            w, h = p.wrapOn(self.canv, self.width - 30 * mm, 50 * mm)
            y += h + 2 * mm
            p.drawOn(self.canv, *self.coord(20 * mm, y))
Ejemplo n.º 14
0
def createBarCodes():
    """
    Create barcode examples and embed in a PDF
    """
    c = canvas.Canvas("barcodes.pdf", pagesize=letter)

    barcode_value = "12345678999M"

    barcode39 = code39.Extended39(barcode_value)
    barcode39Std = code39.Standard39(barcode_value, barHeight=20, stop=1)

    # code93 also has an Extended and MultiWidth version
    barcode93 = code93.Standard93(barcode_value)

    barcode128 = code128.Code128(barcode_value)
    # the multiwidth barcode appears to be broken
    #barcode128Multi = code128.MultiWidthBarcode(barcode_value)

    barcode_usps = usps.POSTNET("50158-9999")

    codes = [barcode39, barcode39Std, barcode93, barcode128, barcode_usps]

    x = 1 * mm
    y = 260 * mm
    x1 = 6.4 * mm

    for code in codes:
        code.drawOn(c, x, y)
        y = y - 30 * mm
    barcode_value = "123456789990"

    # draw the eanbc8 code
    barcode_eanbc8 = eanbc.Ean8BarcodeWidget(barcode_value)
    bounds = barcode_eanbc8.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(50, 10)
    d.add(barcode_eanbc8)
    renderPDF.draw(d, c, 150 * mm, 150 * mm)

    # # draw the eanbc13 code
    barcode_eanbc13 = eanbc.Ean13BarcodeWidget(barcode_value)
    bounds = barcode_eanbc13.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(50, 10)
    d.add(barcode_eanbc13)
    renderPDF.draw(d, c, 150 * mm, 100 * mm)

    # # draw a QR code
    qr_code = qr.QrCodeWidget('www.ghf.com')
    bounds = qr_code.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(45, 45, transform=[45. / width, 0, 0, 45. / height, 0, 0])
    d.add(qr_code)
    renderPDF.draw(d, c, 150 * mm, 50 * mm)

    c.save()
Ejemplo n.º 15
0
 def draw(self):
     qr_code = qr.QrCodeWidget(self.qr_value)
     qr_code.barWidth = self.size
     qr_code.barHeight = self.size
     qr_code.qrVersion = 1
     d = Drawing()
     d.add(qr_code)
     renderPDF.draw(d, self.canv, self.x_offset, self.y_offset)
def genQR(barcode_value):
    qr_code = qr.QrCodeWidget(barcode_value)
    bounds = qr_code.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    size = 55
    d = Drawing(55, 55, transform=[55. / width, 0, 0, 55. / height, 0, 0])
    d.add(qr_code)
    return d
Ejemplo n.º 17
0
def generate_ticket(request, code, **params):

    data = security.decrypt(code)
    ticket = Ticket.objects.get(id=data['ticket']['id'])
    data['time'] = str(datetime.now())
    qr_code = qr.QrCodeWidget(ticket.code())

    # Create the HttpResponse object with the appropriate PDF headers.
    response = HttpResponse(content_type='application/pdf')
    response[
        'Content-Disposition'] = 'attachment; filename="ticket-{}.pdf"'.format(
            ticket.full_id())

    # Create the PDF object, using the response object as its "file."
    p = canvas.Canvas(response, pagesize=A4)

    bounds = qr_code.getBounds()
    qr_width = bounds[2] - bounds[0]
    qr_height = bounds[3] - bounds[1]
    c = Drawing(45,
                45,
                transform=[230. / qr_width, 0, 0, 230. / qr_height, 0, 0])
    c.add(qr_code)
    p.drawImage(ImageReader(ticket.entry.event.ticket_background),
                0,
                0,
                width=A4[0],
                height=A4[1],
                mask='auto',
                preserveAspectRatio=True)

    qr_x = A4[1] * 0.1
    qr_y = A4[0] * 0.3
    renderPDF.draw(c, p, qr_x, qr_y)
    p.drawString(qr_x + 20, qr_y, "Billet #{}".format(ticket.full_id()))

    # Draw things on the PDF. Here's where the PDF generation happens.
    # See the ReportLab documentation for the full list of functionality.
    text_x = qr_x + 2.3 * qr_width + 30
    text_y = qr_y + 1.5 * qr_height
    p.drawString(text_x, text_y, "{} {}".format(ticket.first_name,
                                                ticket.last_name.upper()))
    p.drawString(text_x, text_y - 20, "{}".format(ticket.email))
    p.drawString(text_x, text_y - 40,
                 "{} (TTC)".format(ticket.entry.full_name()))

    p.setFontSize(10)
    p.drawString(
        qr_x, qr_y - 50,
        "Billet vendu et édité par le BdE INSA Lyon, 20 avenue Albert Einstein, "
        "69621 Villeurbanne CEDEX".format(ticket.full_id()))

    # Close the PDF object cleanly, and we're done.
    p.showPage()
    p.save()
    return response
Ejemplo n.º 18
0
 def draw(self):
     """Flowable canvas."""
     a4width, a4height = A4
     qr_code = qr.QrCodeWidget(self.value)
     bounds = qr_code.getBounds()
     width = bounds[2] - bounds[0]
     height = bounds[3] - bounds[1]
     d = Drawing(65, 65, transform=[65. / width, 0, 0, 65. / height, 0, 0])
     d.add(qr_code)
     renderPDF.draw(d, self.canv, 30, height - 90)
Ejemplo n.º 19
0
 def draw(self):
     # here standard and documented QrCodeWidget usage on
     # Flowable canva
     qr_code = qr.QrCodeWidget(self.qr_value)
     bounds = qr_code.getBounds()
     qr_width = bounds[2] - bounds[0]
     qr_height = bounds[3] - bounds[1]
     w = float(self.width)
     d = Drawing(w, w, transform=[w/qr_width, 0, 0, w/qr_height, 0, 0])
     d.add(qr_code)
     renderPDF.draw(d, self.canv, 0, 0)
Ejemplo n.º 20
0
 def draw_qr(self):
     qr_code = qr.QrCodeWidget('www.mousevspython.com')
     bounds = qr_code.getBounds()
     width = bounds[2] - bounds[0]
     height = bounds[3] - bounds[1]
     d = Drawing(0, 0, transform=[60. / width, 0, 0, 60. / height, 0, 0])
     d.add(qr_code)
     self.y_cursor -= height
     renderPDF.draw(d, self.c,
                    self.left_margin + (self.page_width - width) / 2.0,
                    self.y_cursor)
     self.y_cursor -= 15
Ejemplo n.º 21
0
    def draw(self):
        self.text_location = 0
        self.canv.rect(0, 0, self.width, self.height)

        self.canv.rotate(90)
        self.canv.setFont("Helvetica", 16)
        self.canv.drawString(
            25 * mm, -12 * mm, str(self.submission.submission_type.name)
        )
        self.canv.rotate(-90)

        qr_code = qr.QrCodeWidget(self.submission.orga_urls.quick_schedule.full())
        bounds = qr_code.getBounds()
        width = bounds[2] - bounds[0]
        height = bounds[3] - bounds[1]
        drawing = Drawing(45, 45, transform=[45 / width, 0, 0, 45 / height, 0, 0])
        drawing.add(qr_code)
        renderPDF.draw(drawing, self.canv, 15, 10)

        self.render_paragraph(
            Paragraph(self.submission.title, style=self.styles["Title"]), gap=10
        )
        self.render_paragraph(
            Paragraph(
                ", ".join(s.get_display_name() for s in self.submission.speakers.all()),
                style=self.styles["Speaker"],
            )
        )
        self.render_paragraph(
            Paragraph(
                _("{} minutes, #{}, {}, {}").format(
                    self.submission.get_duration(),
                    self.submission.code,
                    self.submission.content_locale,
                    self.submission.state,
                ),
                style=self.styles["Meta"],
            )
        )

        if self.submission.abstract:
            self.render_paragraph(
                Paragraph(
                    ellipsize(self.submission.abstract, 140), style=self.styles["Meta"]
                )
            )

        if self.submission.notes:
            self.render_paragraph(
                Paragraph(
                    ellipsize(self.submission.notes, 140), style=self.styles["Meta"]
                )
            )
Ejemplo n.º 22
0
    def first_pages(canvas, document):
        canvas.saveState()
        canvas.setFont("PTAstraSerifReg", 9)
        # вывести интерактивную форму "текст"
        form = canvas.acroForm
        # canvas.drawString(25, 780, '')
        form.textfield(name='comment',
                       tooltip='comment',
                       fontName='Times-Roman',
                       fontSize=10,
                       x=57,
                       y=750,
                       borderStyle='underlined',
                       borderColor=black,
                       fillColor=white,
                       width=515,
                       height=13,
                       textColor=black,
                       forceBorder=False)

        # Вывести на первой странице код-номер договора
        barcode128.drawOn(canvas, 120 * mm, 283 * mm)

        #вывести внизу QR-code (ФИО, (номера направлений))
        qr_code = qr.QrCodeWidget(qr_value)
        qr_code.barWidth = 70
        qr_code.barHeight = 70
        qr_code.qrVersion = 1
        bounds = qr_code.getBounds()
        width = bounds[2] - bounds[0]
        height = bounds[3] - bounds[1]
        d = Drawing()
        d.add(qr_code)
        renderPDF.draw(d, canvas, 90 * mm, 7)
        #вывести атрибуты для подписей
        canvas.setFont('PTAstraSerifReg', 10)
        canvas.drawString(40 * mm, 10 * mm, '____________________________')
        canvas.drawString(115 * mm, 10 * mm,
                          '/{}/____________________________'.format(npf))
        canvas.setFont('Symbola', 18)
        canvas.drawString(195 * mm, 10 * mm, '\u2713')

        canvas.setFont('PTAstraSerifReg', 8)
        canvas.drawString(50 * mm, 7 * mm, '(подпись сотрудника)')
        canvas.drawString(160 * mm, 7 * mm, '(подпись плательщика)')

        #вывестии защитны вертикальный мелкий текст
        canvas.rotate(90)
        canvas.setFillColor(HexColor(0x4f4b4b))
        canvas.setFont('PTAstraSerifReg', 5.2)
        canvas.drawString(10 * mm, -12 * mm, '{}'.format(6 * left_size_str))

        canvas.restoreState()
Ejemplo n.º 23
0
 def __draw_qr(self, canvas):
     qr_widget = qr.QrCodeWidget(value=self.banner_queue_entrypoint_url())
     bounds = qr_widget.getBounds()
     qr_widget_width = bounds[2] - bounds[0]
     qr_widget_height = bounds[3] - bounds[1]
     transform = [
         self.WIDTH / qr_widget_width, 0, 0, self.HEIGHT / qr_widget_height,
         0, 0
     ]
     qr_drawing = Drawing(self.WIDTH, self.HEIGHT, transform=transform)
     qr_drawing.add(qr_widget)
     renderPDF.draw(qr_drawing, canvas, self.QR_CODE_W, self.QR_CODE_H)
Ejemplo n.º 24
0
def QR():
    print request.form

    output = cStringIO.StringIO()
    c = canvas.Canvas(output)

    inputRows = int(request.form["inputRows"])
    inputColumns = int(request.form["inputColumns"])
    qrSize = float(request.form["qrSize"])
    columnSeparation = int(request.form["columnSeparation"])
    rowSeparation = int(request.form["rowSeparation"])
    leftOffset = int(request.form["leftOffset"])
    bottomOffset = int(request.form["bottomOffset"])

    x = 0
    y = 0
    for bookId in request.form:
        # print bookId
        if bookId.isdigit():
            db = get_db()
            cur = db.execute("select * from books where id=?", [bookId])
            book = cur.fetchone()

            url = url_for('QR_get_title', title=book[1], _external=True)

            qr_code = qr.QrCodeWidget(url)
            bounds = qr_code.getBounds()
            width = bounds[2] - bounds[0]
            height = bounds[3] - bounds[1]
            size = qrSize
            d = Drawing(size,
                        size,
                        transform=[size / width, 0, 0, size / height, 0, 0])
            d.add(qr_code)
            renderPDF.draw(d, c, leftOffset + x * columnSeparation,
                           bottomOffset + 5 + y * rowSeparation)
            c.drawString(leftOffset + x * columnSeparation,
                         bottomOffset + y * rowSeparation, book[1])

            x = (x + 1) % inputColumns
            if x == 0:
                y = (y + 1) % inputRows

    c.save()
    pdf_out = output.getvalue()
    output.close()

    response = make_response(pdf_out)
    response.headers[
        'Content-Disposition'] = "attachment; filename='books_to_print.pdf"
    response.mimetype = 'application/pdf'

    return response
Ejemplo n.º 25
0
def send_pdf(bill_object):
    print bill_object.user
    username = bill_object.user.username
    month = bill_object.month
    bill_unit = bill_object.billing_units
    bill_amount = bill_object.bill_amount
    billname = str(username) + str(month) + ".pdf"
    path = os.path.join(dir_path + "/static", billname)
    c = canvas.Canvas(billname, pagesize=letter)
    c.drawImage('powerheader.jpg', 2, 670, 600, 95)
    c.drawImage('2.jpg', 2, 120, 620, 115)
    c.drawImage('header.jpg', 5, 700)
    c.drawInlineImage('3.jpg', 5, 702, 105, 70)
    c.setFillColor(HexColor('#ffffff'))
    c.setFontSize(size=12)
    c.setFillColor(HexColor('#000000'))
    c.drawString(
        15, 630,
        "--------------------------------------------------------------------------------------------------------------------------------------------------"
    )
    c.drawString(
        15, 200,
        "--------------------------------------------------------------------------------------------------------------------------------------------------"
    )
    #c.drawString(20, 600, "Customer_ID :")
    #c.drawString(250,600,str(bill_object.user.connection.id.customer_id))
    c.drawString(20, 550, "Name:")
    c.drawString(250, 550, username)
    #c.drawString(20,500,"Address:")
    c.drawString(20, 500, "month:")
    c.drawString(20, 500, month)
    #address = (billing_object.user.connection.survey_number+billing_object.user.connection.society_name+billing_object.user.connection.village+billing_object.user.connection.taluka+billing_object.user.connection.district+billing_object.user.connection.pincode)
    #c.drawString(250,500,str(address))
    # c.drawString(20, 450, "Mobile No:")
    # c.drawString(250,450,str(billing_object.user.phone))
    c.drawString(20, 400, "Billing_units:")
    c.drawString(250, 400, bill_unit)
    # c.drawString(20, 350, "Month :")
    # c.drawString(250,350,str(billing_object.month))
    c.drawString(20, 300, "Billing Amount:")
    c.drawString(250, 300, bill_amount)
    # c.drawString(20, 250, "Last Date:")
    # c.drawString(250, 250, str(billing_object.last_date))
    qr_code = qr.QrCodeWidget(bill_object.id)
    bounds = qr_code.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(110, 110, transform=[110. / width, 0, 0, 110. / height, 0, 0])
    d.add(qr_code)
    renderPDF.draw(d, c, 490, 520)
    c.drawImage('3.jpg', 2, -5, 620, 200)
    c.save()
Ejemplo n.º 26
0
def BarCodePdfView(request):
    """
    Create barcode examples and embed in a PDF
    """
    from reportlab.lib.pagesizes import A4, legal, landscape, A3, A5, A6
    size = landscape(A4)

    result = []
    try:
        bags = Bag.objects.filter(status=1)
        for bag in bags:
            c = canvas.Canvas(PDF_ROOT + str(bag.qr_code) + '.pdf',
                              pagesize=A5)
            barcode_value = bag.qr_code
            barcode_name = bag.name
            # draw a QR code
            qr_code = qr.QrCodeWidget(barcode_value)
            width = 10
            height = 15

            d = Drawing(45,
                        45,
                        transform=[45. / width, 0, 0, 45. / height, 0, 0])
            d.add(qr_code)
            renderPDF.draw(d, c, 20, 250)

            c.setLineWidth(10)
            c.setFont('Helvetica', 50)

            # c.line(100,450,500,450)
            # c.drawString(200,400,barcode_name)
            # c.line(100,380,500,380)

            c.line(30, 220, 400, 220)
            c.drawString(120, 170, barcode_name)
            c.line(30, 150, 400, 150)

            c.save()
            result.append(bag.qr_code)
            # import pdb
            # pdb.set_trace()

        # return JsonResponse({'message':'all bags are printed','result':result ,'status_code':200})
    except Exception as e:
        print(e)
        # return JsonResponse({'message':'Only these bags are printed:', 'result':result, 'status_code':500})

    zip_file_loc = shutil.make_archive(ZIP_ROOT + 'Bags', 'zip', PDF_ROOT)
    response = HttpResponse(FileWrapper(open(zip_file_loc, 'rb')),
                            content_type='application/zip')
    response['Content-Disposition'] = 'attachment; filename=Bags.zip'
    return response
Ejemplo n.º 27
0
def qr_code(barcode_value):
    c = canvas.Canvas('pdfs-generated-by-codes/qr_code.pdf')
    qrcode = qr.QrCodeWidget(barcode_value)
    qrcode.barWidth = 145
    qrcode.barHeight = 145
    qrcode.qrVersion = 1
    # bounds = qrcode.getBounds()
    # width = bounds[2] - bounds[1]
    # height = bounds[3] - bounds[1]
    d = Drawing()
    d.add(qrcode)
    renderPDF.draw(d, c, 15, 700)
    c.save()
def send_pdf(bill_object):


    print bill_object.user
    username = bill_object.user.username
    month = bill_object.month
    bill_unit = bill_object.billing_units
    bill_amount = bill_object.bill_amount
    billname = str(username) + str(month) + ".pdf"
    code = str(bill_object.id) + ":" + str(bill_object.bill_amount)
    address = str(bill_object.user.connection.survey_number)+" "+ str(bill_object.user.connection.society_name) +" "+  str(bill_object.user.connection.village)
    address1 = str(bill_object.user.connection.taluka) +" "+  str(bill_object.user.connection.district) +" "+  str(bill_object.user.connection.pincode)
    path = os.path.join(dir_path + "/static", billname)


    c= canvas.Canvas(path, pagesize=letter)
    c.drawImage("/home/shree/Shubham/final project of hacathon/hackathon_user_service-master/user_service/pdf/powerheader.jpg",2,670,600,95)
    c.setFillColor(HexColor('#ffffff'))
    c.setFontSize(size=12)
    c.setFillColor(HexColor('#000000'))
    c.drawString(15,630,"--------------------------------------------------------------------------------------------------------------------------------------------------")
    c.drawString(15,200,"--------------------------------------------------------------------------------------------------------------------------------------------------")
    c.drawString(20, 600, "Customer_ID :")
    c.drawString(250,600,str(bill_object.user.connection.customer_id))
    c.drawString(20, 550, "Name:")
    c.drawString(250,550,bill_object.user.connection.name)
    c.drawString(20,350,"Address:")
    c.drawString(250,350,str(address))
    c.drawString(250,380,str(address1))
    c.drawString(20, 500, "month:")
    c.drawString(250, 500, month)
    print type(code)

    c.drawString(20, 450, "Mobile No:")
    c.drawString(250,450,str(bill_object.user.phone))
    c.drawString(20,400,"Billing_units:")
    c.drawString(250,400,str(bill_unit))
    c.drawString(20, 300, "Billing Amount:")
    c.drawString(250, 300, str(bill_amount))
    c.drawString(20, 250, "Last Date:")
    c.drawString(250, 250, str(bill_object.last_date))
    qr_code = qr.QrCodeWidget(code)
    bounds = qr_code.getBounds()
    width = bounds[2] - bounds[0]
    height = bounds[3] - bounds[1]
    d = Drawing(110, 110, transform=[110. / width, 0, 0, 110. / height, 0, 0])
    d.add(qr_code)
    renderPDF.draw(d, c, 490, 520)
    c.drawImage("/home/shree/Shubham/final project of hacathon/hackathon_user_service-master/user_service/pdf/3.jpg",2,-5,620,200)
    c.save()
    return billname
Ejemplo n.º 29
0
    def print_code_qr(self, x, y, text, taille=10):
        """
		Insert un code QR
		"""
        qr_code = qr.QrCodeWidget(text)
        bounds = qr_code.getBounds()
        width = bounds[2] - bounds[0]
        height = bounds[3] - bounds[1]
        d = Drawing(
            taille * mm / inch,
            taille * mm / inch,
            transform=[taille * mm / inch, 0, 0, taille * mm / inch, 0, 0])
        d.add(qr_code)
        renderPDF.draw(d, self.canvas, x * mm, y * mm)
Ejemplo n.º 30
0
    def draw(self):
        qr_code = qr.QrCodeWidget(self.qr_value)
        bounds = qr_code.getBounds()
        qr_width = bounds[2] - bounds[0]
        qr_height = bounds[3] - bounds[1]

        d = Drawing(self.width,
                    self.height,
                    transform=[
                        self.width / qr_width, 0, 0, self.height / qr_height,
                        0, 0
                    ])
        d.add(qr_code)
        renderPDF.draw(d, self.canv, 0, 0)