Пример #1
0
    def create_prod_labels(self):
        """
        These values should be measured from the printed page.
        In all the following calculations, the bottom left corner of
        the page is considered to be at the origin of the x-y plane.
        All the coordinates should be provided w.r.t. the this origin.
        """
        # page size
        page_H = 297*mm  # A4
        page_W = 210*mm   # A4
        # coordinates of lower left corner of single label w.r.t. origin
        box_X = 16.5*mm
        box_Y = 9.6*mm
        # distance between rows and columns of labels
        box_X_shift = 46.2*mm
        box_Y_shift = 36.0*mm

        pdfmetrics.registerFont(TTFont('Arial', 'ARIALN.TTF'))
        c = Canvas(self.outFile)
        c.setLineWidth(0.1)

        # horizontal lines
        for i in range(7):
            c.line(42*mm + i*box_Y_shift, 10*mm,
                   42*mm + i*box_Y_shift, page_W-10*mm)
        # vertical lines
        for i in range(3):
            c.line(2*mm, 58*mm + i*box_X_shift,
                   page_H-2*mm, 58*mm + i*box_X_shift)

        for i in range(4):
            dx = box_X + i*box_X_shift
            for j in range(8):
                dy = box_Y + j*box_Y_shift
                self.draw_single_label(dy, dx, c)

        c.setPageRotation(90)
        c.setPageSize((page_W, page_H))
        c.save()
        self.message.setText(
            "Creating " + self.outFile.replace(self.cdir, "Documents/"))