Пример #1
0
    def test3(self):
        "Test rotated Image shape adding it to a PDF page."

        inPath = IMAGENAME
        img = Image(0, 0, 110, 44, inPath)
        d = Drawing(110, 44)
        d.add(img)
        d.translate(420, 0)
        d.scale(2, 2)
        d.rotate(45)
        IMAGES.append(d)
Пример #2
0
    def test3(self):
        "Test rotated Image shape adding it to a PDF page."

        inPath = IMAGENAME
        img = Image(0, 0, 110, 44, inPath)
        d = Drawing(110, 44)
        d.add(img)
        d.translate(420, 0)
        d.scale(2, 2)
        d.rotate(45)
        self.IMAGES.append(d)
Пример #3
0
def test_draw():
    sheet = Sheet('draw', margin=0, verbose=0)
    sheet.can.setFillColor('red')
    sheet.can.circle(0, 200, 100, stroke=1, fill=1)
    d = Drawing(200, 200)
    d.add(Rect(100, 0, 100, 120, fillColor=colors.yellow, strokeColor=None))
    d.rotate(-45)
    d.add(Rect(100, 105, 120, 130, fillColor=colors.blue, strokeColor=None))
    #d.rotate(45)
    d.add(String(150, 100, 'Hello World', fontSize=18, fillColor=colors.red))
    #d.scale(0.5,0.5)
    d.wrapOn(sheet.can, 200, 200)
    d.drawOn(sheet.can, 0, 600)
    sheet.save()
Пример #4
0
 def c_square(self, **kwargs):
     """return a drawing  the a^2+b^2 part of the pythagorean"""
     show_grid = kwargs.get('show_grid', 0)
     count_squares = kwargs.get('count_squares', 0)
     drawing = Drawing(self.size, self.size)
     angle = math.atan(1. * self.a / self.b) * 180 / math.pi
     print("fotate:", angle)
     drawing.rotate(angle)
     c = math.pow(self.a * self.a + self.b * self.b, 0.5)
     print("c:", c)
     step = 1. * self.size / (self.a + self.b)
     if show_grid:
         i = 1
         while i <= c:
             drawing.add(
                 Line(0,
                      i * step,
                      self.size,
                      i * step,
                      strokeColor=self.grid_color))
             drawing.add(
                 Line(i * step,
                      0,
                      i * step,
                      self.size,
                      strokeColor=self.grid_color))
             i += 1
     drawing.add(
         Rect(self.a,
              0,
              c,
              c,
              fillColor=self.fill_color,
              strokeColor=self.stroke_color))
     #drawing.rotate(-angle)
     drawing.add(
         Rect(0,
              0,
              self.size,
              self.size,
              fillColor=self.fill_color,
              strokeColor=self.stroke_color))
     return drawing
Пример #5
0
from reportlab.graphics.shapes import Image, Drawing
from reportlab.graphics import renderPDF
from reportlab.lib.pagesizes import A4

imaxes = []
imaxe = Image(150, 50, 589, 202, "/home/dam2a/Descargas/vaca-lechera.jpg")

debuxo = Drawing(500, 102)
debuxo.translate(0, 650)  #movelo de posición
debuxo.add(imaxe)

debuxo2 = Drawing(250, 51)
debuxo2.add(imaxe)
debuxo2.rotate(45)
debuxo2.scale(0.5, 1.5)
debuxo2.translate(150, -45)
imaxes.append(debuxo2)

imaxes.append(debuxo)
documento = Drawing(A4[0], A4[1])

for elemento in imaxes:
    documento.add(elemento)

renderPDF.drawToFile(documento, "segundoInforme.pdf")
from reportlab.lib.pagesizes import A4

imaxes = []

imaxe = Image(400, 0, 596, 133, "/home/manuel/Imaxes/200.jpg")

debuxo = Drawing(30, 30)
debuxo.add(imaxe)
debuxo.translate(0, 0)
imaxes.append(debuxo)

debuxo = Drawing(30, 30)
debuxo.add(imaxe)

debuxo.scale(1.5, 0.5)
debuxo.translate(-300, 300)
debuxo.rotate(45)
imaxes.append(debuxo)

debuxo = Drawing(30, 30)
debuxo.add(imaxe)
debuxo.rotate(theta=60)
debuxo.translate(-400, 00)
imaxes.append(debuxo)

debuxo = Drawing(A4[0], A4[1])

for aux in imaxes:
    debuxo.add(aux)
renderPDF.drawToFile(debuxo, "probaInformes3.pdf")
from reportlab.graphics.shapes import Image, Drawing
from reportlab.graphics import renderPDF
from reportlab.lib.pagesizes import A4
guion = []
imaxe = Image(400,10,596,133,"hackerman.png")
debuxo = Drawing(30,30)
debuxo.add(imaxe)
debuxo.translate(0, 600)
guion.append(debuxo)
debuxo = Drawing(30,30)
debuxo.add(imaxe)
debuxo.rotate(45)
debuxo.scale(1.5, 0.5)
debuxo.translate(-90, 300)
guion.append(debuxo)
debuxo = Drawing(30,30)
debuxo.add(imaxe)
debuxo.rotate(90)
debuxo.translate(-20, -100)
guion.append(debuxo)
debuxo = Drawing(A4[0], A4[1])
for deb in guion:
    debuxo.add(deb)
renderPDF.drawToFile(debuxo, "proba2.pdf")
p = canvas.Canvas(path + "/qr_codes.pdf")

for model_name in os.listdir(path):

    # Only visible dirs
    if model_name[0] == ".":
        continue

    # Generate qr code
    qrw = QrCodeWidget(model_name)
    b = qrw.getBounds()
    w=b[2]-b[0]
    h=b[3]-b[1]

    d = Drawing(1,1,transform=[5,0,0,5,0,0])
    d.rotate(90)
    d.translate(0,-90)
    d.add(qrw)

    # Generate the rectangle
    r = Rect(1,1,1,1)

    renderPDF.draw(d, p, 0, 0)
    #renderPDF.draw(r, p, 0, 0)

    x_offset = 0;
    y_offset = 2;

    o = 30
    a = 390
    w = 30
p = canvas.Canvas(path + "/qr_codes.pdf")

for model_name in os.listdir(path):

    # Only visible dirs
    if model_name[0] == ".":
        continue

    # Generate qr code
    qrw = QrCodeWidget(model_name)
    b = qrw.getBounds()
    w = b[2] - b[0]
    h = b[3] - b[1]

    d = Drawing(1, 1, transform=[5, 0, 0, 5, 0, 0])
    d.rotate(90)
    d.translate(0, -90)
    d.add(qrw)

    # Generate the rectangle
    r = Rect(1, 1, 1, 1)

    renderPDF.draw(d, p, 0, 0)
    #renderPDF.draw(r, p, 0, 0)

    x_offset = 0
    y_offset = 2

    o = 30
    a = 390
    w = 30
Пример #10
0
class PDFMaker(object):  # creazione classe PDFMaker
    """"""
    def __init__(self, pdf_file, namestation,
                 id):  # funzione init per la classe PDFMaker
        self.c = canvas.Canvas(pdf_file,
                               pagesize=letter)  # indica il foglio di lavoro
        self.styles = getSampleStyleSheet()  # indica lo stile del foglio
        self.width, self.height = letter  # larghezza e altezza hanno dimensioni lettera, formato preimpostato
        self.namestation = namestation  # indica il nome della stazione
        self.id = id  # indica l'id della stazione

    def createDocument(self):  # funzione che crea il documento
        """"""
        voffset = 65  # offset verticale

        # add a logo and size it
        logo = Image('Image_pdf/Meta-logo.jpg')  # indica la path dell'immagine
        logo.drawHeight = 3 * inch  # indica l'alteza dell'immagine
        logo.drawWidth = 3.5 * inch  # indica la larghezza dell'immagine
        logo.wrapOn(
            self.c, self.width,
            self.height)  # indica l'impostazione dell'immagine nel foglio
        logo.drawOn(self.c, *self.coord(
            65, 80, mm))  # disegna la foto a coordinate fissate 65,80, mm

        address = """<font size="24">
		Stazione di %s%s</font>
        """ % (self.namestation, self.id
               )  # indica il nome della stazione corrente
        p = Paragraph(
            address,
            self.styles["Normal"])  # creazione di un paragrafo di testo
        p.wrapOn(self.c, self.width,
                 self.height)  # importazione del testo nel foglio
        if len(
                self.namestation
        ) == 6:  # if fatti per centrare il nome della stazione nel foglio
            self.X = 188
        elif len(self.namestation) == 3:
            self.X = 223
        elif len(self.namestation) == 4:
            self.X = 214
        elif len(self.namestation) == 5:
            self.X = 205
        elif len(self.namestation) == 7:
            self.X = 180
        elif len(self.namestation) == 8:
            self.X = 175
        elif len(self.namestation) == 9:
            self.X = 172
        elif len(self.namestation) == 10:
            self.X = 168
        elif len(self.namestation) == 11:
            self.X = 164
        elif len(self.namestation) == 12:
            self.X = 160
        elif len(self.namestation) == 13:
            self.X = 156
        elif len(self.namestation) == 14:
            self.X = 152
        elif len(self.namestation) == 15:
            self.X = 148
        elif len(self.namestation) == 16:
            self.X = 144
        elif len(self.namestation) == 17:
            self.X = 140
        elif len(self.namestation) == 18:
            self.X = 136
        elif len(self.namestation) == 19:
            self.X = 132
        elif len(self.namestation) == 20:
            self.X = 128
        elif len(self.namestation) == 21:
            self.X = 124
        elif len(self.namestation) == 22:
            self.X = 120
        elif len(self.namestation) == 23:
            self.X = 116
        p.drawOn(self.c, *self.coord(self.X,
                                     195))  # diesgna il testo a coordinate...

        tMedia = """<font size="12">
		<b>Temperatura media</b></font>
		"""                  # paragrafo di testo
        self.createParagraph(tMedia, 18, voffset + 25)  # creazione paragrafo
        data = [[
            "Dati attesi", "Dati effettivi", "Percentuale di funzionamento"
        ], [valTot, valPresTMED, "%d" % (percTMED) + "%"]]  # dati per tabella
        table = Table(data, colWidths=2 * inch)  # inizializzazione tabella
        table.setStyle([("VALIGN", (-1, -1), (-1, -1), "TOP"),
                        ("GRID", (0, 0), (-1, -1), 1, colors.black),
                        ("GRID", (0, 0), (-1, 0), 1, colors.black)
                        ])  # stile tabella
        table.wrapOn(self.c, self.width,
                     self.height)  # importazione nel foglio della tabella
        table.drawOn(self.c,
                     *self.coord(18, 105,
                                 mm))  # disegno della tabella a coordinate...

        umid = """<font size="12">
		<b>Umidità</b></font>
		"""
        self.createParagraph(umid, 18, voffset + 50)
        data = [[
            "Dati attesi", "Dati effettivi", "Percentuale di funzionamento"
        ], [valTot, valPresUMID, "%d" % (percUMID) + "%"]]
        table = Table(data, colWidths=2 * inch)
        table.setStyle([("VALIGN", (0, 0), (0, 0), "TOP"),
                        ("GRID", (0, 0), (-1, -1), 1, colors.black),
                        ("GRID", (0, 0), (-1, 0), 1, colors.black)])
        table.wrapOn(self.c, self.width, self.height)
        table.drawOn(self.c, *self.coord(18, 130, mm))

        piogg = """<font size="12">
		<b>Pioggia</b></font>
		"""
        self.createParagraph(piogg, 18, voffset + 75)
        data = [[
            "Dati attesi", "Dati effettivi", "Percentuale di funzionamento"
        ], [valTot, valPresPG, "%d" % (percPG) + "%"]]
        table = Table(data, colWidths=2 * inch)
        table.setStyle([("VALIGN", (0, 0), (0, 0), "TOP"),
                        ("GRID", (0, 0), (-1, -1), 1, colors.black),
                        ("GRID", (0, 0), (-1, 0), 1, colors.black)])
        table.wrapOn(self.c, self.width, self.height)
        table.drawOn(self.c, *self.coord(18, 155, mm))

        bagnFogl = """<font size="12">
		<b>Bagnatura fogliare</b></font>
		"""
        self.createParagraph(bagnFogl, 18, voffset + 100)
        data = [[
            "Dati attesi", "Dati effettivi", "Percentuale di funzionamento"
        ], [valTot, valPresFB, "%d" % (percFB) + "%"]]
        table = Table(data, colWidths=2 * inch)
        table.setStyle([("VALIGN", (0, 0), (0, 0), "TOP"),
                        ("GRID", (0, 0), (-1, -1), 1, colors.black),
                        ("GRID", (0, 0), (-1, 0), 1, colors.black)])
        table.wrapOn(self.c, self.width, self.height)
        table.drawOn(self.c, *self.coord(18, 180, mm))

        velVento = """<font size="12">
		<b>Velocità vento</b></font>
		"""
        self.createParagraph(velVento, 18, voffset + 125)
        data = [[
            "Dati attesi", "Dati effettivi", "Percentuale di funzionamento"
        ], [valTot, valPresVenVel,
            "%d" % (percVenVel) + "%"]]
        table = Table(data, colWidths=2 * inch)
        table.setStyle([("VALIGN", (0, 0), (0, 0), "TOP"),
                        ("GRID", (0, 0), (-1, -1), 1, colors.black),
                        ("GRID", (0, 0), (-1, 0), 1, colors.black)])
        table.wrapOn(self.c, self.width, self.height)
        table.drawOn(self.c, *self.coord(18, 205, mm))

        radSolare = """<font size="12">
		<b>Radiazione solare</b></font>
		"""
        self.createParagraph(radSolare, 18, voffset + 150)
        data = [[
            "Dati attesi", "Dati effettivi", "Percentuale di funzionamento"
        ], [valTot, valPresRAD, "%d" % (percRAD) + "%"]]
        table = Table(data, colWidths=2 * inch)
        table.setStyle([("VALIGN", (0, 0), (0, 0), "TOP"),
                        ("GRID", (0, 0), (-1, -1), 1, colors.black),
                        ("GRID", (0, 0), (-1, 0), 1, colors.black)])
        table.wrapOn(self.c, self.width, self.height)
        table.drawOn(self.c, *self.coord(18, 230, mm))

        self.c.showPage()  # per iniziare una nuova pagina

        self.drawing = Drawing(200, 400)  # disegna figura vuota
        self.drawing.rotate(-90)  # ruota figura vuota
        self.data = [(percRAD, percVenVel, percFB, percPG, percUMID, percTMED)
                     ]  #dati per il grafico
        self.names = [
            "Radiazione solare", "Velocità vento", "Bagnatura fogliare",
            "Pioggia", "Umidità", "Temperatura media"
        ]  #nomi per grafico
        self.bc = HorizontalBarChart()  # inizializzazione grafico orizzontale
        self.bc.x = 20  # x del grafico
        self.bc.y = 50  # y del grafico
        self.bc.height = 400  # altezza del grafico
        self.bc.width = 600  # larghezza grafico
        self.bc.data = self.data  # dati del grafico sono uguali a data
        self.bc.strokeColor = colors.white  # colore del grafico
        self.bc.valueAxis.valueMin = 0  # valore minimo asse
        self.bc.valueAxis.valueMax = 100  # valore massimo asse
        self.bc.valueAxis.valueStep = 5  # step di 5 dell'asse
        self.bc.categoryAxis.labels.boxAnchor = 'ne'  # non importante
        self.bc.categoryAxis.labels.dx = -10  # etichettatura grafico
        self.bc.categoryAxis.labels.fontName = 'Helvetica'  # font garfico
        self.bc.categoryAxis.categoryNames = self.names  # asse dei nomi, quello sotto
        self.drawing.add(self.bc)  # aggiunta del grafico alla figura vuota
        renderPDF.draw(self.drawing, self.c, 40,
                       700)  # disegmo del grafico sul pdf

        self.d = Drawing(0, 0)
        self.d.rotate(-90)
        self.c.rotate(-90)
        self.c.setFont('Helvetica', 30)
        self.cb = self.c.drawString(
            -600, 525, "Percentuale di funzionamento"
        )  # creazione titolo per grafico ruotato di -90 gradi
        self.d.add(
            self.cb
        )  # la x è negativa perchè anche le coordinate cambiano in base al punto di orgine
        renderPDF.draw(self.d, self.c, 100, 100)

    def coord(
        self,
        x,
        y,
        unit=1
    ):  # funzione ripresa da internet per la collocazione in base alle coordinate
        """
		# http://stackoverflow.com/questions/4726011/wrap-text-in-a-table-reportlab
    	Helper class to help position flowables in Canvas objects
    	"""
        x, y = x * unit, self.height - y * unit
        return x, y

    def createParagraph(self,
                        ptext,
                        x,
                        y,
                        style=None):  # funzione che crea un paragrafo
        """"""
        if not style:
            style = self.styles["Normal"]
            p = Paragraph(ptext, style=style)
            p.wrapOn(self.c, self.width, self.height)
            p.drawOn(self.c, *self.coord(x, y, mm))

    def savePDF(self):  # funzione che salva il pdf
        """"""
        self.c.save()
Пример #11
0
from reportlab.graphics.shapes import Image, Drawing
from reportlab.lib.pagesizes import A4

guion = []
imagen = Image(
    400, 10, 596, 133,
    "/home/local/DANIELCASTELAO/fsancheztemprano/Imágenes/triforce.jpg")

dibujo = Drawing(30, 30)
dibujo.add(imagen)
dibujo.translate(0, 600)
guion.append(dibujo)

dibujo = Drawing(30, 30)
dibujo.add(imagen)
dibujo.rotate(45)
dibujo.scale(1.5, 0.5)
dibujo.translate(-90, 300)
guion.append(dibujo)

dibujo = Drawing(30, 30)
dibujo.add(imagen)
dibujo.rotate(90)
dibujo.translate(-20, -100)
guion.append(dibujo)

dibujo = Drawing(A4[0], A4[1])
for deb in guion:
    dibujo.add(deb)

renderPDF.drawToFile(dibujo, "prueba2.pdf")