Beispiel #1
0
    def run_emmod_ao_ploe09(self):

        def pagina_com_logotipo():
            topo = '/home/leandro/Câmara/logo/topo__margem.jpg'
            rodape = '/home/leandro/Câmara/logo/rodape_margem.jpg'

            packet = io.BytesIO()
            try:
                can = canvas.Canvas(
                    packet, pagesize=landscape(A4))  # landscape(A4)

                #can.setFillColorRGB(255, 255, 0, 1)
                #can.setFillColorCMYK(0, 0, 0, 0, 1)
                #can.rect(v['xf'], v['yf'], v['wf'], v['hf'], stroke=0, fill=1)
                largura = 595
                can.drawImage(topo, 0, 746, largura, 400 / 2500 * largura)

                #can.setFillColorCMYK(0, 0, 0, 0, 1)
                #can.rect(v['xh'], v['yh'], v['wh'], v['hh'], stroke=0, fill=1)
                can.drawImage(rodape, 0, 0, largura, 150 / 1700 * largura)

                #can.setFillColorCMYK(0, 0, 0, 1, 1)
                # can.setFontSize(9)
                # can.drawString(
                ##    v['xh'] + 250, v['yh'] + 45,
                #   'AUTÓGRAFO Nº 641, DE 13 DE DEZEMBRO DE 2019.')

                can.save()

            except Exception as e:
                print(e)

            packet.seek(0)

            pagina = PdfFileReader(packet)
            return pagina

        ofile = PdfFileWriter()
        vo = '/home/leandro/Downloads/EMMOD_AO__PLOE09__timbrado.pdf'

        ifile = PdfFileReader(
            open('/home/leandro/Downloads/EMMOD_AO__PLOE09.pdf', "rb"))

        for num_page in range(ifile.getNumPages()):

            pl = pagina_com_logotipo()

            p = ifile.getPage(num_page)

            p.mergePage(pl.getPage(0))
            ofile.addPage(p)

        outputStream = open(vo, "wb")
        ofile.write(outputStream)
        outputStream.close()
def get_images(path):
    images = []
    r = PdfFileReader(open(path, "rb"))
    cnt = counter.Counter()

    for i in range(0, r.numPages):
        page = r.getPage(i)

        if '/XObject' in page['/Resources']:
            xObject = page['/Resources']['/XObject'].getObject()

            for obj in xObject:
                if xObject[obj]['/Subtype'] == '/Image':
                    size = (xObject[obj]['/Width'], xObject[obj]['/Height'])
                    data = xObject[obj].getData()

                    if xObject[obj]['/ColorSpace'] == '/DeviceRGB':
                        mode = "RGB"
                    else:
                        mode = "P"

                    write_path = constants.PATH_TEMP + str(cnt.iteration)

                    if '/Filter' in xObject[obj]:
                        if xObject[obj]['/Filter'] == '/FlateDecode':
                            img = Image.frombytes(mode, size, data)
                            write_image(img, data)
                            images.append(write_path + obj[1:] + ".png")

                        elif xObject[obj]['/Filter'] == '/DCTDecode':
                            img = open(write_path + ".jpg", "wb")
                            write_image(img, data)
                            images.append(write_path + ".jpg")

                        elif xObject[obj]['/Filter'] == '/JPXDecode':
                            img = open(write_path + obj[1:] + ".jp2", "wb")
                            write_image(img, data)
                            images.append(write_path + obj[1:] + ".jp2")

                        elif xObject[obj]['/Filter'] == '/CCITTFaxDecode':
                            img = open(write_path + obj[1:] + ".tiff", "wb")
                            write_image(img, data)
                            images.append(write_path + obj[1:] + ".tiff")
                    else:
                        img = Image.frombytes(mode, size, data)
                        write_image(img, data)
                        images.append(write_path + obj[1:] + ".png")

                    cnt.iterate()

    return images
Beispiel #3
0
    def run_veririca_pdf_tem_assinatura(self):
        global sss
        sss = 1

        def tree_print(field_name, fields):
            global sss
            ss = " "
            print(ss * sss, field_name, '.............')
            if not isinstance(fields, dict):
                ByteStringObject
                if field_name == '/Contents':
                    try:
                        signed_data = cms.ContentInfo.load(fields)['content']

                        for cert in signed_data['certificates']:
                            print('cert.issuer:',
                                  cert.native['tbs_certificate']['issuer'])
                            print('cert.subject:',
                                  cert.native['tbs_certificate']['subject'])

                    except Exception as e:
                        pass

                    with open(
                            '/home/leandro/Downloads/content{}.ext'.format(
                                sss), 'wb') as f:
                        f.write(fields)
                        f.close()
                    return
                else:
                    print(' ' * sss, fields)
                    return
            for field_name, value in fields.items():
                sss += 2
                tree_print(field_name, value)
                sss -= 2

        ifile = '/home/leandro/Downloads/016 - Projeto da LDO 2021_Assinado.pdf'
        ifile = '/home/leandro/Downloads/plol_violencia_nas_escolas.pdf'

        (hashok, signatureok, certok) = pdf.verify(open(ifile, 'rb').read())
        print('signature ok?', signatureok)
        print('hash ok?', hashok)
        print('cert ok?', certok)

        r = PdfFileReader(open(ifile, "rb"))

        fields = r.getFields()

        tree_print('file', fields)
Beispiel #4
0
        def pagina_com_logotipo(v):
            logo_camara = '/home/leandro/Câmara/logo/logo_256.jpg'
            logo_horizontal = '/home/leandro/Câmara/logo/logo_horizontal.jpg'

            packet = io.BytesIO()
            try:
                can = canvas.Canvas(
                    packet, pagesize=landscape(A4))  # landscape(A4)

                #can.setFillColorRGB(255, 255, 0, 1)
                can.setFillColorCMYK(0, 0, 0, 0, 1)
                can.rect(v['xf'], v['yf'], v['wf'], v['hf'], stroke=0, fill=1)
                can.drawImage(logo_camara, v['x'], v['y'], v['w'], v['h'])

                can.setFillColorCMYK(0, 0, 0, 0, 1)
                can.rect(v['xh'], v['yh'], v['wh'], v['hh'], stroke=0, fill=1)

                can.drawImage(logo_horizontal,
                              v['xh'], v['yh'], v['wh'], v['hh'])

                can.setFillColorCMYK(0, 0, 0, 1, 1)
                can.setFontSize(9)
                can.drawString(
                    v['xh'] + 250, v['yh'] + 45,
                    'AUTÓGRAFO Nº 641, DE 13 DE DEZEMBRO DE 2019.')

                can.save()

            except Exception as e:
                print(e)

            packet.seek(0)

            pagina = PdfFileReader(packet)
            return pagina
Beispiel #5
0
        def pagina_com_logotipo():
            topo = '/home/leandro/Câmara/logo/topo__margem.jpg'
            rodape = '/home/leandro/Câmara/logo/rodape_margem.jpg'

            packet = io.BytesIO()
            try:
                can = canvas.Canvas(
                    packet, pagesize=landscape(A4))  # landscape(A4)

                #can.setFillColorRGB(255, 255, 0, 1)
                #can.setFillColorCMYK(0, 0, 0, 0, 1)
                #can.rect(v['xf'], v['yf'], v['wf'], v['hf'], stroke=0, fill=1)
                largura = 595
                can.drawImage(topo, 0, 746, largura, 400 / 2500 * largura)

                #can.setFillColorCMYK(0, 0, 0, 0, 1)
                #can.rect(v['xh'], v['yh'], v['wh'], v['hh'], stroke=0, fill=1)
                can.drawImage(rodape, 0, 0, largura, 150 / 1700 * largura)

                #can.setFillColorCMYK(0, 0, 0, 1, 1)
                # can.setFontSize(9)
                # can.drawString(
                ##    v['xh'] + 250, v['yh'] + 45,
                #   'AUTÓGRAFO Nº 641, DE 13 DE DEZEMBRO DE 2019.')

                can.save()

            except Exception as e:
                print(e)

            packet.seek(0)

            pagina = PdfFileReader(packet)
            return pagina
Beispiel #6
0
 def validate_file(self, file):
     """Check that the file sent is an image or if it is a pdf."""
     if not imghdr.what(file):
         try:
             from io import BytesIO
             PdfFileReader(BytesIO(file.read()))
         except Exception:
             raise serializers.ValidationError(
                 'File should be an image or a pdf.')
     return file
Beispiel #7
0
    def join_documents(self, out_filepath):
        output_pdf = PdfFileWriter()
        logger.debug("Created output pdf object")
        fileinsts = list()
        for filename in self.tempfiles:
            fileinst = open(filename, "rb")
            pdffile = PdfFileReader(fileinst)
            logger.debug("merging %s in output pdf" % filename)
            for pageNum in range(pdffile.numPages):
                page = pdffile.getPage(pageNum)
                output_pdf.addPage(page)
            fileinsts.append(fileinst)

        logger.debug("Writing output pdf to %s" % out_filepath)
        fileinst = open(out_filepath, "wb")
        output_pdf.write(fileinst)
        fileinst.close()
        for infileinst in fileinsts:
            infileinst.close()
Beispiel #8
0
        def pagina_com_logotipo(v):
            logo_camara = '/home/leandro/Câmara/logo/logo_256.jpg'
            logo_horizontal = '/home/leandro/Câmara/logo/logo_horizontal.jpg'

            packet = io.BytesIO()
            try:
                can = canvas.Canvas(packet,
                                    pagesize=landscape(A4))  # landscape(A4)

                #can.setFillColorRGB(255, 255, 0, 1)
                can.setFillColorCMYK(0, 0,
                                     255 if partes_ou_completo == 'P' else 0,
                                     0, 1)
                can.rect(v['xf'], v['yf'], v['wf'], v['hf'], stroke=0, fill=1)
                can.drawImage(logo_camara, v['x'], v['y'], v['w'], v['h'])

                can.setFillColorCMYK(0, 0,
                                     255 if partes_ou_completo == 'P' else 0,
                                     0, 1)

                can.rect(v['xfh'],
                         v['yfh'],
                         v['wfh'],
                         v['hfh'],
                         stroke=0,
                         fill=1)

                can.drawImage(logo_horizontal, v['xh'], v['yh'], v['wh'],
                              v['hh'])

                can.setFillColorCMYK(0, 0, 0, 1, 1)
                can.setFontSize(9)
                can.drawString(v['xh'] + v['wh'] * 0.62,
                               v['yh'] + v['hh'] - 12, epigrafe)

                can.save()

            except Exception as e:
                print(e)

            packet.seek(0)

            pagina = PdfFileReader(packet)
            return pagina
Beispiel #9
0
def toCSVContent(file):
    reader = PdfFileReader(file)
    text = to_lines(get_raw_text(reader))
    return '\n'.join(titles() + to_csv_generator(text))
Beispiel #10
0
    def run_autografo(self,
                      arquivos=None,
                      epigrafe='',
                      partes_ou_completo='C'):
        def pagina_com_logotipo(v):
            logo_camara = '/home/leandro/Câmara/logo/logo_256.jpg'
            logo_horizontal = '/home/leandro/Câmara/logo/logo_horizontal.jpg'

            packet = io.BytesIO()
            try:
                can = canvas.Canvas(packet,
                                    pagesize=landscape(A4))  # landscape(A4)

                #can.setFillColorRGB(255, 255, 0, 1)
                can.setFillColorCMYK(0, 0,
                                     255 if partes_ou_completo == 'P' else 0,
                                     0, 1)
                can.rect(v['xf'], v['yf'], v['wf'], v['hf'], stroke=0, fill=1)
                can.drawImage(logo_camara, v['x'], v['y'], v['w'], v['h'])

                can.setFillColorCMYK(0, 0,
                                     255 if partes_ou_completo == 'P' else 0,
                                     0, 1)

                can.rect(v['xfh'],
                         v['yfh'],
                         v['wfh'],
                         v['hfh'],
                         stroke=0,
                         fill=1)

                can.drawImage(logo_horizontal, v['xh'], v['yh'], v['wh'],
                              v['hh'])

                can.setFillColorCMYK(0, 0, 0, 1, 1)
                can.setFontSize(9)
                can.drawString(v['xh'] + v['wh'] * 0.62,
                               v['yh'] + v['hh'] - 12, epigrafe)

                can.save()

            except Exception as e:
                print(e)

            packet.seek(0)

            pagina = PdfFileReader(packet)
            return pagina

        if partes_ou_completo == 'P':
            vo = ''
            for i, o, v in arquivos:

                ofile = PdfFileWriter()
                vo = o

                ifile = PdfFileReader(open(i, "rb"))

                if v:
                    xy = []
                    for num_page in range(ifile.getNumPages()):
                        xy.append(v)

                for num_page in range(ifile.getNumPages()):

                    if v:
                        pl = pagina_com_logotipo(v)
                    p = ifile.getPage(num_page)
                    if v:
                        p.mergePage(pl.getPage(0))

                    ofile.addPage(p)

                outputStream = open(vo, "wb")
                ofile.write(outputStream)
                outputStream.close()
        else:

            ofile = PdfFileWriter()
            vo = ''

            for i, o, v in arquivos:
                if not v:
                    vo = o

                ifile = PdfFileReader(open(i, "rb"))

                if v:
                    xy = []
                    for num_page in range(ifile.getNumPages()):
                        xy.append(v)

                for num_page in range(ifile.getNumPages()):

                    if v:
                        pl = pagina_com_logotipo(v)
                    p = ifile.getPage(num_page)
                    if v:
                        p.mergePage(pl.getPage(0))

                    ofile.addPage(p)

            outputStream = open(vo, "wb")
            ofile.write(outputStream)
            outputStream.close()
Beispiel #11
0
 def fromFile(self, filename):
     self.filename = filename
     self.f = open(filename, "rb")
     PdfFileReader.__init__(self, self.f)
Beispiel #12
0
    def run_ploe41_2019(self):

        def pagina_com_logotipo(v):
            logo_camara = '/home/leandro/Câmara/logo/logo_256.jpg'
            logo_horizontal = '/home/leandro/Câmara/logo/logo_horizontal.jpg'

            packet = io.BytesIO()
            try:
                can = canvas.Canvas(
                    packet, pagesize=landscape(A4))  # landscape(A4)

                #can.setFillColorRGB(255, 255, 0, 1)
                can.setFillColorCMYK(0, 0, 0, 0, 1)
                can.rect(v['xf'], v['yf'], v['wf'], v['hf'], stroke=0, fill=1)
                can.drawImage(logo_camara, v['x'], v['y'], v['w'], v['h'])

                can.setFillColorCMYK(0, 0, 0, 0, 1)
                can.rect(v['xh'], v['yh'], v['wh'], v['hh'], stroke=0, fill=1)

                can.drawImage(logo_horizontal,
                              v['xh'], v['yh'], v['wh'], v['hh'])

                can.setFillColorCMYK(0, 0, 0, 1, 1)
                can.setFontSize(9)
                can.drawString(
                    v['xh'] + 250, v['yh'] + 45,
                    'AUTÓGRAFO Nº 641, DE 13 DE DEZEMBRO DE 2019.')

                can.save()

            except Exception as e:
                print(e)

            packet.seek(0)

            pagina = PdfFileReader(packet)
            return pagina

        arquivos = (
            (
                '/home/leandro/TEMP/autografos/PLOE-41/autografo/autografo641.pdf',
                '/home/leandro/TEMP/autografos/PLOE-41/autografo/autografo641__completo.pdf',
                {}
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-41/autografo/a01.pdf',
                '/home/leandro/TEMP/autografos/PLOE-41/autografo/a01__out.pdf',
                {
                    'x': 57,
                    'y': 499,
                    'w': 93,
                    'h': 68,
                    'xf': 56,
                    'yf': 493,
                    'wf': 95,
                    'hf': 80,

                    'xh': 155,
                    'yh': 518,
                    'wh': 359,
                    'hh': 57,

                }
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-41/autografo/a02.pdf',
                '/home/leandro/TEMP/autografos/PLOE-41/autografo/a02__out.pdf',
                {
                    'x': 57,
                    'y': 499,
                    'w': 93,
                    'h': 68,
                    'xf': 56,
                    'yf': 493,
                    'wf': 95,
                    'hf': 80,

                    'xh': 155,
                    'yh': 518,
                    'wh': 359,
                    'hh': 57,
                }
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-41/autografo/a03.pdf',
                '/home/leandro/TEMP/autografos/PLOE-41/autografo/a03__out.pdf',
                {
                    'x': 57,
                    'y': 499,
                    'w': 93,
                    'h': 68,
                    'xf': 56,
                    'yf': 493,
                    'wf': 95,
                    'hf': 80,

                    'xh': 155,
                    'yh': 518,
                    'wh': 359,
                    'hh': 57,
                }
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-41/autografo/a04.pdf',
                '/home/leandro/TEMP/autografos/PLOE-41/autografo/a04__out.pdf',
                {
                    'x': 57,
                    'y': 499,
                    'w': 93,
                    'h': 68,
                    'xf': 56,
                    'yf': 493,
                    'wf': 95,
                    'hf': 80,

                    'xh': 155,
                    'yh': 518,
                    'wh': 359,
                    'hh': 57,
                }
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-41/autografo/a05.pdf',
                '/home/leandro/TEMP/autografos/PLOE-41/autografo/a05__out.pdf',
                {
                    'x': 57,
                    'y': 499,
                    'w': 93,
                    'h': 68,
                    'xf': 56,
                    'yf': 493,
                    'wf': 95,
                    'hf': 80,

                    'xh': 155,
                    'yh': 518,
                    'wh': 359,
                    'hh': 57,
                }
            ),
        )

        ofile = PdfFileWriter()
        vo = ''
        for i, o, v in arquivos:
            if not v:
                vo = o

            ifile = PdfFileReader(open(i, "rb"))

            if v:
                xy = []
                for num_page in range(ifile.getNumPages()):
                    xy.append(v)

            #xy[1] = 400, 100

            for num_page in range(ifile.getNumPages()):

                if v:
                    pl = pagina_com_logotipo(v)

                p = ifile.getPage(num_page)

                if v:
                    p.mergePage(pl.getPage(0))
                ofile.addPage(p)

        outputStream = open(vo, "wb")
        ofile.write(outputStream)
        outputStream.close()
Beispiel #13
0
    def run_ploe42_2019(self):

        def pagina_com_logotipo(v):
            logo_camara = '/home/leandro/Câmara/logo/logo_256.jpg'
            logo_horizontal = '/home/leandro/Câmara/logo/logo_horizontal.jpg'

            packet = io.BytesIO()
            try:
                can = canvas.Canvas(
                    packet, pagesize=landscape(A4))  # landscape(A4)

                #can.setFillColorRGB(255, 255, 0, 1)
                can.setFillColorCMYK(0, 0, 0, 0, 1)
                can.rect(v['xf'], v['yf'], v['wf'], v['hf'], stroke=0, fill=1)
                can.drawImage(logo_camara, v['x'], v['y'], v['w'], v['h'])

                can.setFillColorCMYK(0, 0, 0, 1, 1)
                can.line(v['xh'], v['yh'] - 1, v['xh'] + 400, v['yh'] - 1)

                can.setFillColorCMYK(0, 0, 0, 0, 1)
                can.rect(v['xh'], v['yh'], v['wh'], v['hh'], stroke=0, fill=1)

                can.drawImage(logo_horizontal,
                              v['xh'], v['yh'], v['wh'] - 100, v['hh'])

                can.setFillColorCMYK(0, 0, 0, 1, 1)
                can.setFontSize(9)
                can.drawString(
                    v['xh'] + 215, v['yh'] + 37,
                    'AUTÓGRAFO Nº 639, DE 13 DE DEZEMBRO DE 2019.')

                can.save()

            except Exception as e:
                print(e)

            packet.seek(0)

            pagina = PdfFileReader(packet)
            return pagina

        coordenadas = coordenadas_a01 = {
            'x': 83, 'y': 478, 'w': 115, 'h': 83,
            'xf': 80, 'yf': 475, 'wf': 121, 'hf': 95,
            'xh': 205, 'yh': 522, 'wh': 450, 'hh': 48,
        }
        coordenadas_a02 = {
            'x': 34, 'y': 478, 'w': 115, 'h': 83,
            'xf': 31, 'yf': 475, 'wf': 121, 'hf': 95,
            'xh': 158, 'yh': 522, 'wh': 450, 'hh': 48,
        }
        coordenadas_a03 = {
            'x': 59, 'y': 478, 'w': 115, 'h': 83,
            'xf': 56, 'yf': 475, 'wf': 121, 'hf': 93,
            'xh': 182, 'yh': 522, 'wh': 450, 'hh': 48,
        }
        coordenadas_a07 = {
            'x': 59, 'y': 485, 'w': 112, 'h': 83,
            'xf': 56, 'yf': 480, 'wf': 117, 'hf': 93,
            'xh': 178, 'yh': 528, 'wh': 450, 'hh': 48,
        }
        coordenadas_a08 = {
            'x': 44, 'y': 479, 'w': 112, 'h': 83,
            'xf': 41, 'yf': 476, 'wf': 117, 'hf': 93,
            'xh': 167, 'yh': 523, 'wh': 450, 'hh': 48,
        }
        arquivos = (
            (
                '/home/leandro/TEMP/autografos/PLOE-42/autografo639.pdf',
                '/home/leandro/TEMP/autografos/PLOE-42/autografo639__completo.pdf',
                {}
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-42/a01.pdf',
                '/home/leandro/TEMP/autografos/PLOE-42/a01__out.pdf',
                coordenadas_a01
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-42/a02.pdf',
                '/home/leandro/TEMP/autografos/PLOE-42/a02__out.pdf',
                coordenadas_a02
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-42/a03.pdf',
                '/home/leandro/TEMP/autografos/PLOE-42/a03__out.pdf',
                coordenadas_a03
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-42/a04.pdf',
                '/home/leandro/TEMP/autografos/PLOE-42/a04__out.pdf',
                coordenadas_a03
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-42/a05.pdf',
                '/home/leandro/TEMP/autografos/PLOE-42/a05__out.pdf',
                coordenadas_a03
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-42/a06.pdf',
                '/home/leandro/TEMP/autografos/PLOE-42/a06__out.pdf',
                coordenadas_a03
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-42/a07.pdf',
                '/home/leandro/TEMP/autografos/PLOE-42/a07__out.pdf',
                coordenadas_a07
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-42/a08.pdf',
                '/home/leandro/TEMP/autografos/PLOE-42/a08__out.pdf',
                coordenadas_a08
            ),
            (
                '/home/leandro/TEMP/autografos/PLOE-42/a09.pdf',
                '/home/leandro/TEMP/autografos/PLOE-42/a09__out.pdf',
                coordenadas_a03
            ),
        )

        ofile = PdfFileWriter()
        vo = ''
        for i, o, v in arquivos:
            if not v:
                vo = o

            ifile = PdfFileReader(open(i, "rb"))

            if v:
                xy = []
                for num_page in range(ifile.getNumPages()):
                    xy.append(v)

            #xy[1] = 400, 100

            for num_page in range(ifile.getNumPages()):

                if v:
                    pl = pagina_com_logotipo(v)

                p = ifile.getPage(num_page)

                if v:
                    p.mergePage(pl.getPage(0))
                ofile.addPage(p)

        outputStream = open(vo, "wb")
        ofile.write(outputStream)
        outputStream.close()
Beispiel #14
0
def run_signed_name_and_date_extract(file):
    signs = {}
    fields = {}
    pdfdata = file.read()

    # se não tem byterange então não é assinado
    byterange = []
    n = -1
    while True:
        n = pdfdata.find(b"/ByteRange", n + 1)
        if n == -1:
            break
        byterange.append(n)

    if not byterange:
        return signs

    # tenta extrair via /Fields
    try:
        pdf = PdfFileReader(file)
        fields = pdf.getFields()
    except Exception as e:
        try:
            pdf = PdfFileReader(file, strict=False)
            fields = pdf.getFields()
        except Exception as ee:
            fields = ee

    try:
        # se a extração via /Fields ocorrer sem erros e forem capturadas
        # tantas assinaturas quanto byteranges
        if isinstance(fields, dict):
            signs = run_signed_name_and_date_via_fields(fields)
            if len(signs) == len(byterange):
                return signs
    except Exception as e:
        pass

    for n in byterange:

        start = pdfdata.find(b"[", n)
        stop = pdfdata.find(b"]", start)
        assert n != -1 and start != -1 and stop != -1
        n += 1

        br = [int(i, 10) for i in pdfdata[start + 1:stop].split()]
        contents = pdfdata[br[0] + br[1] + 1:br[2] - 1]
        bcontents = bytes.fromhex(contents.decode("utf8"))
        data1 = pdfdata[br[0]:br[0] + br[1]]
        data2 = pdfdata[br[2]:br[2] + br[3]]
        #signedData = data1 + data2

        nome = 'Nome do assinante não localizado.'
        try:
            signed_data = cms.ContentInfo.load(bcontents)['content']
            oun_old = []
            for cert in signed_data['certificates']:
                subject = cert.native['tbs_certificate']['subject']
                oun = subject['organizational_unit_name']

                if isinstance(oun, str):
                    continue

                if len(oun) > len(oun_old):
                    oun_old = oun
                    nome = subject['common_name'].split(':')[0]

                if nome not in signs:
                    signs[nome] = timezone.localtime()
        except:
            pass

    return signs
Beispiel #15
0
 def check_last_tempfile(self):
     fileinst = open(self.tempfiles[-1], "rb")
     pdffile = PdfFileReader(fileinst)
     self.current_start_page += pdffile.numPages
     fileinst.close()
Beispiel #16
0
 def __open_pdf(self) -> PdfFileReader:
     """
     Open PDF as bytes
     @return: 'PdfFileReader' object
     """
     return PdfFileReader(open(self.input_file, mode="rb"))