Ejemplo n.º 1
0
def firstPageSR():
    from reportlab.pdfgen.canvas import Canvas
    from reportlab.platypus import Paragraph, Frame
    from reportlab.lib.colors import orange

    c = Canvas("out/firstPageSR.pdf", landscape(A4))
    body = Frame(cm, cm, 19 * cm, 20 * cm, showBoundary=1)
    right = Frame(20 * cm, cm, 6 * cm, 20 * cm, showBoundary=1)
    style = ParagraphStyle(styles["Normal"])
    style2 = styles["BodyText"]
    style.textColor = orange
    style.fontSize = 60

    imgPhoenix = Image("phoenix.jpg", 5 * cm, 5 * cm)
    imgPhoenix.hAlign = 'RIGHT'
    imgPhoenix.vAlign = 'TOP'
    imgOrange = Image("orange.jpg", 2 * cm, 2 * cm)
    imgOrange.hAlign = 'RIGHT'
    imgOrange.vAlign = 'BOTTOM'
    StoryRight = [imgPhoenix]
    p = Paragraph("Team Beluga", style2)
    StoryRight.append(p)
    StoryRight.append(imgOrange)

    StoryBody = [Paragraph("<b>Sprint Review</b>", style)]
    p = Paragraph("Sprint N 13", style2)
    StoryBody.append(p)

    body.addFromList(StoryBody, c)
    right.addFromList(StoryRight, c)
    c.save()
Ejemplo n.º 2
0
def extract_images(bs, directory):
    SCALING_FACTOR = 0.5
    image_list = []
    for tag in bs.findAll('img'):
        # get source link for images in entry
        image_file = moodle.download_image(tag['src'], directory)
        tag['src'] = image_file
        width = int(float(tag['width']) * SCALING_FACTOR)
        tag['width'] = str(width)
        height = int(float(tag['height']) * SCALING_FACTOR)
        tag['height'] = str(height)
        # tag['valign'] = 'super', 'baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom', '0%', '2in'
        # tag.parent['spaceAfter'] = '2cm'
        tag.decompose()
        i = Image(image_file, width=width, height=height)
        i.vAlign = 'TOP'
        image_list.append(i)
    return image_list
Ejemplo n.º 3
0
 def __init__(self, instance):
     # Configuración
     filename = ruta + 'media/kids/guias/%d.pdf' % instance.id
     self.estilos = {
         'texto': ParagraphStyle(name='texto',
             alignment=TA_JUSTIFY,
             fontName='PatrickHand',
             fontSize=12,
             leading=17,
             firstLineIndent=20,
             ),
         'pregunta': ParagraphStyle(name='pregunta',
             alignment=TA_JUSTIFY,
             fontName='PatrickHand',
             fontSize=12,
             leading=20,
             firstLineIndent=30,
             ),
         'puntos': ParagraphStyle(name='puntos',
             alignment=TA_JUSTIFY,
             fontName='PatrickHand',
             fontSize=12,
             leading=25,
             ),
         'cabecera': ParagraphStyle(name='cabecera',
             alignment=TA_RIGHT,
             fontName='GloriaHallelujah',
             fontSize=9,
             leading=14,
             textColor='#444444',
             ),
         'titulo': ParagraphStyle(name='titulo',
             alignment=TA_CENTER,
             fontName='PermanentMarker',
             fontSize=20,
             leading=20,
             textColor='#00338e',
             ),
         'subtitulo': ParagraphStyle(name='subtitulo',
             alignment=TA_JUSTIFY,
             fontName='Julee',
             fontSize=14,
             leading=20,
             textColor='#00338e',
         ),
         'versiculo': ParagraphStyle(name='versiculo',
             alignment=TA_RIGHT,
             fontName='PatrickHand',
             fontSize=12,
             leading=14,
             firstLineIndent=100,
         ),
         'pupiletras': ParagraphStyle(name='pupiletras',
             alignment=TA_CENTER,
             fontName='DroidSansMono',
             fontSize=12,
             leading=15,
         ),
     }
     self.story = []
     self.header = 'Iglesia "La Palabra y El Espíritu"'
     BaseDocTemplate.__init__(self, filename)
     self.mostrar = 0
     self.allowSplitting = 1
     self.showBoundary = self.mostrar
     self.MARGEN = 0.5 * cm
     a4 = A4
     margen = self.MARGEN
     frameDatos = Frame(self.MARGEN * 2, self.MARGEN,
         A4[0] - 4 * self.MARGEN, A4[1] - 4 * self.MARGEN,
         id='datos', showBoundary=self.mostrar)
     height = frameDatos.height
     template = PageTemplate('pagina_normal', [frameDatos],
         self.formato)
     self.addPageTemplates(template)
     self.insertar(instance.nombre, 'titulo')
     self.insertar(u'Versículos de Estudio', 'subtitulo')
     estilo = 'texto'
     for linea in instance.versiculo.splitlines():
         self.insertar(linea, estilo)
         if estilo == 'texto':
             estilo = 'versiculo'
         else:
             estilo = 'texto'
     self.insertar(u'Bosquejo', 'subtitulo')
     estilo = 'texto'
     for linea in instance.bosquejo.splitlines():
         self.insertar(linea, estilo)
     self.insertar('Temas', 'subtitulo')
     for linea in instance.temas.splitlines():
         self.insertar('- ' + linea, 'texto')
     self.story.append(PageBreak())
     alto = 20
     alto += self.insertar(instance.nombre, 'titulo')
     alto += self.insertar(u'Versículo Para Memorizar', 'subtitulo')
     estilo = 'texto'
     for linea in instance.memorizar.splitlines():
         alto += self.insertar(linea, estilo)
         if estilo == 'texto':
             estilo = 'versiculo'
         else:
             estilo = 'texto'
     alto += self.insertar('Ejercicios Espirituales', 'subtitulo')        
     for linea in instance.ejercicios.splitlines():
         alto += self.insertar('- ' + linea, 'texto')
     ej = instance.ejercicios
     ruta_logo = instance.imagen
     url = ruta_logo.path
     img = utils.ImageReader(url)
     iw, ih = img.getSize()
     aspect = ih / float(iw)
     resta = int(height) - alto - 10
     logo = Image(url, width=(resta / aspect), height=resta)
     self.story.append(logo)
     logo.hAlign = 'CENTER'
     logo.vAlign = 'BOTTOM'
     self.insertar('Preguntas', 'subtitulo')
     i = 0
     for linea in instance.preguntas.splitlines():
         i += 1
         self.insertar(str(i) +'.- ' + linea, 'pregunta')
         self.insertar(97 * '. ', 'puntos')
         self.insertar(97 * '. ', 'puntos')
     self.insertar('Completa y Resuelve el Pupiletras', 'subtitulo')
     palabras = []
     for linea in instance.historia.splitlines():
         ps, l = self.parse(linea)
         palabras += ps
         self.insertar(l, 'texto')
     pupiletras = Pupiletras(palabras)
     pupi = unicode(pupiletras)
     self.story.append(Spacer(0, 20))
     for linea in pupi.splitlines():
         self.insertar(linea, 'pupiletras')
     NumberedCanvas(filename)
     self.build(self.story)
Ejemplo n.º 4
0
def makePdf(npm_mahasiswa, nama_mahasiswa, tipe_bimbingan,
            kode_dosen_pembimbing, nama_pembimbing, nidn_pembimbing,
            tahun_ajaran, photo, judul, total_nilai, elements, logo, styles,
            kode_dosen_koordinator):
    checkDir()
    makeQrcodeVerifySign(link=makeLinkVerify(kode_dosen=kode_dosen_pembimbing,
                                             npm_mahasiswa=npm_mahasiswa,
                                             tipe_bimbingan=tipe_bimbingan,
                                             total_nilai=total_nilai),
                         kode_dosen=kode_dosen_pembimbing,
                         npm_mahasiswa=npm_mahasiswa,
                         tipe_bimbingan=tipe_bimbingan)
    makeQrcodeVerifySign(link=makeLinkVerify(kode_dosen=kode_dosen_koordinator,
                                             npm_mahasiswa=npm_mahasiswa,
                                             tipe_bimbingan=tipe_bimbingan,
                                             total_nilai=total_nilai),
                         kode_dosen=kode_dosen_koordinator,
                         npm_mahasiswa=npm_mahasiswa,
                         tipe_bimbingan=tipe_bimbingan)
    bulan = date.today().strftime("%m")
    d2 = date.today().strftime(f"%d {bkd.bulanSwitcher(bulan)} %Y")
    elements.append(logo)

    ptext = '<font name="Times" size="14">BERITA ACARA</font>'
    elements.append(Paragraph(ptext, styles["Center"]))
    elements.append(Spacer(1, 12))

    ptext = f'<font name="Times" size="14">{switcherTipeBimbingan(tipe_bimbingan)}</font>'
    elements.append(Paragraph(ptext, styles["Center"]))
    elements.append(Spacer(1, 12))

    ptext = '<font name="Times" size="14">TA. ' + tahun_ajaran + '</font>'
    elements.append(Paragraph(ptext, styles["Center"]))
    elements.append(Spacer(1, 0.5 * inch))

    image = Image(photo, 1.1 * inch, 1.5 * inch)
    image.hAlign = "RIGHT"
    elements.append(image)
    elements.append(Spacer(1, 1.5 * inch))

    ptext = '<font size=12> </font>'
    elements.append(Paragraph(ptext, styles["Center"]))
    elements.append(Spacer(1, -3 * inch))

    table = [[
        '<font name="Times" size="12">Nama</font>',
        '<font name="Times" size="12">: ' + nama_mahasiswa + '</font>'
    ],
             [
                 '<font name="Times" size="12">Npm</font>',
                 '<font name="Times" size="12">: ' + npm_mahasiswa + '</font>'
             ],
             [
                 '<font name="Times" size="12">Judul</font>',
                 '<font name="Times" size="12">: ' + judul + '</font>'
             ],
             [
                 '<font name="Times" size="12">Pembimbing</font>',
                 '<font name="Times" size="12">: ' + nama_pembimbing +
                 '</font>'
             ]]

    style = TableStyle([('ALIGN', (1, 1), (-2, -2), 'RIGHT'),
                        ('VALIGN', (0, 0), (0, -1), 'TOP'),
                        ('ALIGN', (0, -1), (-1, -1), 'LEFT'),
                        ('VALIGN', (0, -1), (-1, -1), 'MIDDLE')])

    s = getSampleStyleSheet()
    s = s["BodyText"]
    s.wordWrap = 'CJK'
    data1 = [[Paragraph(cell, s) for cell in row] for row in table]
    tab = Table(data1, hAlign='LEFT', colWidths=[75, 290])
    tab.setStyle(style)

    elements.append(tab)
    elements.append(Spacer(1, 0.6 * inch))

    data = [[
        'Pertemuan', 'Tanggal', 'Sudah Dikerjakan', 'Pekerjaan Selanjutnya',
        'Nilai'
    ]]
    inner_data_list = makeListDataBimbinganByDosens(npm_mahasiswa,
                                                    kode_dosen_pembimbing)
    for i in inner_data_list:
        data.append(i)
    nilai_data_list = [
        '', '', '', 'Rata-Rata: ',
        "%.2f" % round(float(total_nilai), 2)
    ]
    data.append(nilai_data_list)

    style = TableStyle([('FONT', (0, 0), (-1, 0), 'Helvetica-Bold'),
                        ('ALIGN', (0, 0), (-1, 0), 'CENTER'),
                        ('VALIGN', (0, 0), (0, -1), 'MIDDLE'),
                        ('ALIGN', (0, 0), (0, -1), 'CENTER'),
                        ('VALIGN', (0, -1), (-1, -1), 'MIDDLE'),
                        ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
                        ('INNERGRID', (0, 0), (-1, -1), 0.50, colors.black),
                        ('BOX', (0, 0), (-1, -1), 0.25, colors.black)])

    s = getSampleStyleSheet()
    s = s["Normal"]
    s.wordWrap = 'CJK'
    data2 = [[Paragraph(cell, s) for cell in row] for row in data]
    t = Table(data2, hAlign='CENTER', colWidths=[62.5, 65, 180, 180, 40])
    t.setStyle(style)

    elements.append(t)
    elements.append(Spacer(1, 10))

    # ptext = '<font size=12> </font>'
    # elements.append(Paragraph(ptext, styles["Right"]))
    # elements.append(Spacer(1, .5 * inch))

    bulan = date.today().strftime("%m")
    tanggal = date.today().strftime(f"%d {bkd.bulanSwitcher(bulan)} %Y")

    data = approve_kambing.getDataPembimbing(npm_mahasiswa,
                                             kode_dosen_pembimbing)
    pembimbingke = approve_kambing.pembimbingPositionAs(
        data, kode_dosen_pembimbing)
    qrcode_pembimbing = f"./beritaacarapitakqrcode/{npm_mahasiswa}-{kode_dosen_pembimbing}-{tipe_bimbingan}.PNG"
    if approve_kambing.cekApprovalTrueorFalse(
            npm_mahasiswa, pembimbingke.replace('pembimbing', 'koordinator')):
        qrcode_koordinator = f"./beritaacarapitakqrcode/{npm_mahasiswa}-{kode_dosen_koordinator}-{tipe_bimbingan}.PNG"
    else:
        qrcode_koordinator = f"./beritaacarapitakqrcode/whiteimage.png"

    image_pembimbing = Image(qrcode_pembimbing, 1.4 * inch, 1.4 * inch)
    image_pembimbing.vAlign = "CENTER"
    image_pembimbing.hAlign = "CENTER"
    image_koordinator = Image(qrcode_koordinator, 1.4 * inch, 1.4 * inch)
    image_koordinator.hAlign = "CENTER"
    image_koordinator.vAlign = "CENTER"

    data = [
        [
            '',
            Paragraph(f'<font name="Times">Bandung, {tanggal}</font>',
                      styles["Center"]), ''
        ],
        [
            Paragraph('<font name="Times"><b>Koordinator</b></font>',
                      styles["Center"]), '',
            Paragraph('<font name="Times"><b>Pembimbing</b></font>',
                      styles["Center"])
        ],
        [image_koordinator, '', image_pembimbing],
        [
            Paragraph(
                f'<font name="Times"><b>{kelas.getNamaDosen(kode_dosen_koordinator)}</b></font>',
                styles["Justify"]), '',
            Paragraph(
                f'<font name="Times"><b>{kelas.getNamaDosen(kode_dosen_pembimbing)}</b></font>',
                styles["Justify"])
        ],
        [
            Paragraph(
                f'<font name="Times"><b>NIDN. {kelas.getAllDataDosens(kode_dosen_koordinator)[2]}</b></font>',
                styles["Justify"]), '',
            Paragraph(
                f'<font name="Times"><b>NIDN. {nidn_pembimbing}</b></font>',
                styles["Justify"])
        ],
    ]

    table = Table(data, [7 * cm, 4.3 * cm, 7 * cm],
                  [1 * cm, .5 * cm, 3.5 * cm, .5 * cm, .5 * cm])
    table.setStyle(
        TableStyle([
            ('FONT', (0, 0), (-1, -1), 'Times-Roman', 12),
            ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
            # ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
            # ('BOX', (0,0), (-1,-1), 0.25, colors.black),
        ]))

    elements.append(table)
Ejemplo n.º 5
0
 def addCover(self, coverImageFile):
     image = Image(coverImageFile, _WF, _HF)
     image.vAlign = 'TOP'
     self._story.append(image)
     self._story.append(PageBreak())
Ejemplo n.º 6
0
 def addCover(self, cover_image):
     image = Image(cover_image, _WF, _HF)
     image.vAlign = 'TOP'
     self._story.append(image)
     self._story.append(PageBreak())
Ejemplo n.º 7
0
results1 = [15,23,42,56,76]
results2 = [34,67,94,31,56]


########   Now lets put everything together.   ########

# create a list and add the elements of our document (image, paragraphs, table, chart) to it
story = []

#define the style for our paragraph text
styles = getSampleStyleSheet()
styleN = styles['Normal']

#First add the Vizard Logo
im = Image("C:\Users\oskar\Documents\doc_no_backup\python_crap\pics/pytrade_logo.png", width=1*inch, height=1*inch)
im.vAlign = 'LEFT'              #can do hAlign
story.append(im)


#add the title
# story.append(Paragraph("<strong>Results for Vizard Experiment</strong>",styleN))
story.append(Paragraph("<strong>Results for Vizard Experiment</strong>",styles["Heading1"]))
# print help(getSampleStyleSheet)
story.append(Spacer(1,.25*inch))

# #convert data to paragraph form and then add paragraphs
# story.append(Paragraph(dataToParagraph(subject1, results1),styleN))
# story.append(Spacer(1,.25*inch))
# story.append(Paragraph(dataToParagraph(subject2, results2),styleN))
# story.append(Spacer(1,.5*inch))