def test():
        # logging.basicConfig(level=logging.INFO)
        query = HKEX_API(from_date=n_yearsago(n=1), to_date=today())
        for data in query.data:
            try:
                url = data.file_link
                # url = 'https://www.dropbox.com/'
                print(url)

                pdf = PDF(url)
                pdf_obj = pdf.pdf_obj
                f = AuditFee(pdf_obj) 
                tab_sum = []
                for table in f.tables:
                    tab_sum.append(table.summary)
            except KeyboardInterrupt:
                break
            except Exception as e:
                # print(e)
                result = {
                'table_summary' : e,
                'ERROR': True,
                'url' : url,
                }
                write_to_csv(result,  'result_3.csv')
                continue
            else:
                # print('ok')
                result = {
                'table_summary' : list(filter(None, tab_sum)),
                'ERROR': None,
                'url' : url
                }
                write_to_csv(result,  'result_3.csv')
Exemplo n.º 2
0
def create_individual_pdfs(revue):
    path = revue.conf["Paths"]

    # Create front pages for individual actors, if they don't already exist:
    frontpages_list = []

    for actor in revue.actors:
        file_name = "forside-{}.pdf".format(actor.name)
        if not os.path.isfile(os.path.join(path["pdf cache"], file_name)):
            tex = TeX(revue)
            tex.create_frontpage(subtitle=actor.name)
            frontpages_list.append([tex, file_name])

    # Create front pages:
    conv = cv.Converter()
    conv.parallel_textopdf(frontpages_list, outputdir=path["pdf cache"])

    total_list = []
    for actor in revue.actors:
        individual_list = (os.path.join(path["pdf cache"], "forside-{}.pdf".format(actor.name)),
                             os.path.join(path["pdf"],"aktoversigt.pdf"),
                             os.path.join(path["pdf"],"rolleliste.pdf"),
                             actor,
                             os.path.join(path["pdf"],"rekvisitliste.pdf"))
        total_list.append((individual_list,
                           os.path.join(path["individual pdf"],
                                       "{}.pdf".format(actor.name))))

    pdf = PDF()
    pdf.parallel_pdfmerge(total_list)
Exemplo n.º 3
0
def create_song_manus_pdf(revue):
    path = revue.conf["Paths"]

    # Create front page, if it doesn't already exist:
    # if not os.path.exists(os.path.join(path["pdf"], "cache")):
    #     os.mkdir(os.path.join(path["pdf"], "cache"))

    # if not os.path.isfile(os.path.join(path["pdf"], "cache", "forside-sangmanuskript.pdf")):
    # Det tager vare på sig selv nu
    tex = TeX(revue)
    tex.create_frontpage(subtitle="sangmanuskript")
    tex.topdf("forside-sangmanuskript.pdf",
              outputdir=os.path.join(path["pdf"], "cache"))

    # Create song manuscript:
    file_list = [
        os.path.join(path["pdf"], "cache", "forside-sangmanuskript.pdf")
    ]
    for act in revue.acts:
        for material in act.materials:
            if material.category == path["songs"]:
                file_list.append((os.path.join(
                    path["pdf"],
                    os.path.dirname(os.path.relpath(material.path)),
                    "{}.pdf".format(material.file_name[:-4])), material.title))

    pdf = PDF()
    pdf.pdfmerge(file_list, os.path.join(path["pdf"], "sangmanuskript.pdf"))
Exemplo n.º 4
0
def gen_pdf_quiz(cfg):
    for user in cfg:
        pdf = PDF()
        for i in range(cfg[user]['global']['pages']):
            pdf.add_page()
            pdf.set_title('四则运算练习')
            pdf.set_date(date=cfg[user]['global']['show_date'])
            quizzes = bulk_quiz_gen(cfg[user])
            pdf.set_quizzes(quizzes=quizzes)
        quiz_dir = cfg[user]['global']['quiz_dir']
        quiz_dir = os.path.expanduser(quiz_dir)
        pdf_filename = os.path.join(quiz_dir,
                                    f'{user}.pdf' if user else 'quizzes.pdf')
        pdf.output(f'{pdf_filename}', 'F')
Exemplo n.º 5
0
def print_aso_bib(participant, copies=2):
    license_holder = participant.license_holder
    copies = int(copies)

    pdf = PDF(orientation='P')
    pdf.set_subject('Bib number and rider info in aso format.')
    pdf.set_keywords(
        'RaceDB CrossMgr Bicycle Racing Software Database Road Time Trial MTB CycloCross RFID'
    )

    for c in xrange(copies):
        aso_bib(pdf, participant.bib, license_holder.first_name,
                license_holder.last_name, participant.competition.name)

    return pdf.output(dest='s')
Exemplo n.º 6
0
def print_aso_bib_two_per_page(participant):

    pdf = PDF(orientation='P')
    pdf.set_subject(
        'Bib number and rider info in modified aso format, two per page.')
    pdf.set_keywords(
        'RaceDB CrossMgr Bicycle Racing Software Database Road Time Trial MTB CycloCross RFID'
    )

    license_holder = participant.license_holder
    aso_bib_two_per_page(pdf, participant.bib, license_holder.first_name,
                         license_holder.last_name,
                         participant.competition.name)

    return pdf.output(dest='s')
Exemplo n.º 7
0
    def __init__(self, settings):
        self.context = None

        self.totalCount = 0
        self.cfbf = CFBF()
        self.pdf = PDF()
        self.ooxml = OOXML()

        self.xls_result = []
        self.ppt_result = []
        self.doc_result = []
        self.xlsx_result = []
        self.pptx_result = []
        self.docx_result = []
        self.PyPDF_result = []
        self.PDFNoModule_result = []
Exemplo n.º 8
0
	def doExport( self, event=None ):
		race = Model.race
		if not race:
			return
		
		fileName = Utils.getMainWin().fileName if Utils.getMainWin() else 'Test.cmn'
		
		#---------------------------------------------------------------------------------
		# Create an Excel file.
		#
		xlFileName = os.path.splitext(fileName)[0] + '-TeamResults.xlsx'

		try:
			wb = xlsxwriter.Workbook( xlFileName )
			formats = ExportGrid.ExportGrid.getExcelFormatsXLSX( wb )
			
			ues = Utils.UniqueExcelSheetName()
			for category in race.getCategories( publishOnly=True ):			
				eg = self.toExportGrid( category )
				if eg:
					ws = wb.add_worksheet( ues.getSheetName(category.fullname) )
					eg.toExcelSheetXLSX( formats, ws )
			wb.close()
		except Exception as e:
			logException( e, sys.exc_info() )
		del wb
		
		#---------------------------------------------------------------------------------
		# Create a PDF file.
		#
		pdfFileName = os.path.splitext(fileName)[0] + '-TeamResults.pdf'
		
		try:
			pdf = PDF( orientation = 'P' )
			pdf.set_font( 'Arial', '', 12 )
			pdf.set_author( getpass.getuser() )
			pdf.set_keywords( 'CrossMgr Team Results' )
			pdf.set_creator( Version.AppVerName )
			pdf.set_title( os.path.splitext(pdfFileName)[0].replace('-', ' ') )
			for category in race.getCategories( publishOnly=True ):
				eg = self.toExportGrid( category )
				if eg:
					eg.drawToFitPDF( pdf, orientation=wx.PORTRAIT )
			pdf.output( pdfFileName, 'F' )
		except Exception as e:
			logException( e, sys.exc_info() )
		del pdf
    def debug(url, p):
        pdf = PDF(url)
        pdf_obj = pdf.pdf_obj
        f = AuditFee(pdf_obj)

        section = f.target_section(p)
        print(section.extract_text())

        table = AuditFeeTable(section)
        # print('curr_idx:', table.currency_idx)
        # print("amount_idx:", table.amount_idx)
        # print("year_idx", table.year_idx)
        # print("co_row_idx:", table.co_row_idx)
        # print("co_col_idx:",table.co_col_idx)

        # print(table.raw_table)
        print(table.table)
        print(table.summary)
Exemplo n.º 10
0
def create_individual_pdfs(revue):
    path = revue.conf["Paths"]

    ## Create front pages for individual actors, if they don't already exist:
    # frontpages_list = []

    # for actor in revue.actors:
    #     file_name = "forside-{}.pdf".format(actor.name)
    #     if not os.path.isfile(os.path.join(path["pdf cache"], file_name)):
    #         tex = TeX(revue)
    #         tex.create_frontpage(subtitle=actor.name)
    #         frontpages_list.append([tex, file_name])

    # Det burde ordne sig selv nu:
    def tex_for_front_page(name):
        tex = TeX(revue)
        tex.create_frontpage(subtitle=name)
        return tex

    frontpages_list = [[
        tex_for_front_page(actor.name), "forside-{}.pdf".format(actor.name)
    ] for actor in revue.actors]

    # Create front pages:
    conv = cv.Converter()
    conv.parallel_textopdf(frontpages_list, outputdir=path["pdf cache"])

    total_list = []
    for actor in revue.actors:
        individual_list = ((os.path.join(path["pdf cache"],
                                         "forside-{}.pdf".format(actor.name)),
                            "Forside"), (os.path.join(path["pdf"],
                                                      "aktoversigt.pdf"),
                                         "Aktoversigt"),
                           (os.path.join(path["pdf"], "rolleliste.pdf"),
                            "Rolleliste"), actor,
                           (os.path.join(path["pdf"],
                                         "kontaktliste.pdf"), "Kontaktliste"))
        total_list.append((individual_list,
                           os.path.join(path["individual pdf"],
                                        "{}.pdf".format(actor.name))))

    pdf = PDF()
    pdf.parallel_pdfmerge(total_list)
Exemplo n.º 11
0
    def OnPrintPage(self, page):
        exportGrid = self.prepareGrid(page)

        try:
            category = self.pageInfo[page][0]
        except Exception as e:
            # Handle case of no data.
            return True

        pageNumber = self.pageInfo[page][3]
        pageTotal = self.pageInfo[page][4]

        fname = u'{fileBase}-{categoryName}.pdf'.format(
            fileBase=self.fileBase,
            categoryName=category.fullname
            if category != 'Primes' else 'Primes')
        fname = Utils.RemoveDisallowedFilenameChars(fname).replace(' ', '-')

        if not self.pdf:
            self.pdf = PDF(
                orientation='L' if self.orientation == wx.LANDSCAPE else 'P')
            self.pdf.set_font('Arial', '', 12)
            self.pdf.set_author(
                unicode(getpass.getuser()).encode('iso-8859-1', 'ignore'))
            self.pdf.set_keywords(
                unicode('CrossMgr Results').encode('iso-8859-1', 'ignore'))
            self.pdf.set_creator(
                unicode(Version.AppVerName).encode('iso-8859-1', 'ignore'))
            self.pdf.set_title(
                unicode(os.path.splitext(fname)[0].replace('-', ' ')).encode(
                    'iso-8859-1', 'ignore'))

        exportGrid.drawToFitPDF(*([self.pdf, self.orientation] +
                                  self.pageInfo[page][1:-1]))

        if not self.allInOne and pageNumber == pageTotal:
            if self.dir and not os.path.isdir(self.dir):
                os.mkdir(self.dir)
            fname = os.path.join(self.dir, fname)
            self.pdf.output(fname, 'F')
            self.lastFName = fname
            self.pdf = None

        return True
Exemplo n.º 12
0
def process_pdf(input_path, db_feed):
    '''
    kicks off pdf processing
    db_feed - pdf json from db
    input_path - path to pdf
    '''

    # initializing pdf object & set parameters
    pdf_object = PDF(db_feed)

    # parsing pdf - input path (?)
    pdf_content = PDFparser().parse(input_path)

    # building dataframe
    df = PDFparser().create_df(pdf_content, pdf_object.page_pattern,
                               pdf_object.table_pattern, pdf_object.column)

    # continue df transformation & filtering only if parsing success
    if (df is not None):
        return process_df(pdf_object, df)
    else:
        print('no dataframe passed')
Exemplo n.º 13
0
def main():

    args = parse()

    # opciones
    pdf = PDF()
    pdf.input_title()
    if args.clear:
        data_clear(pdf)
    elif args.cities:
        compare_city(args.cities, pdf)
    elif args.states:
        compare_state(args.states, pdf)
    elif args.type:
        compare_restaurant(pdf, args.type)
    else:
        print(
            'Error: se requiere uno o mas argumentos para realizar la accion. Pulsa -h para más información'
        )

    url_pdf = url + "/../pdf/"
    pdf.output(url_pdf + "analytic.pdf", 'F')
Exemplo n.º 14
0
def print_bib_on_rect(bib,
                      license_code=None,
                      name=None,
                      logo=None,
                      widthInches=5.9,
                      heightInches=3.9,
                      copies=1,
                      onePage=False):
    page_width = widthInches * inches_to_points
    page_height = heightInches * inches_to_points

    pdf = PDF('L', (page_height * (copies if onePage else 1), page_width))
    pdf.set_author(RaceDBVersion)
    pdf.set_title('Race Bib Number: {}'.format(bib))
    pdf.set_subject('Bib number.')
    pdf.set_creator(getpass.getuser())
    pdf.set_keywords(
        'RaceDB CrossMgr Bicycle Racing Software Database Road Time Trial MTB CycloCross RFID'
    )
    pdf.add_font('din1451alt',
                 style='',
                 fname=get_font_file('din1451alt G.ttf'),
                 uni=True)

    margin = min(page_height, page_width) / 17.5
    sep = margin / 2.5

    height = page_height - margin * 2.0
    width = page_width - margin * 2.0

    text_margin = margin
    text_height = margin * 0.4

    for c in xrange(copies):
        if c == 0 or not onePage:
            pdf.add_page()
            page_y = 0
        else:
            page_y = page_height * c
            pdf.dashed_line(0, page_y, page_width, page_y, space_length=12)

        pdf.set_font('din1451alt', '', 16)
        field = Rect(margin, margin + page_y, width, height)
        field.draw_text_to_fit(pdf, bib, Rect.AlignCenter | Rect.AlignMiddle)

        pdf.set_font('Helvetica')
        if logo:
            x = text_margin
            logo_rect = Rect(x, page_height - margin + page_y,
                             (page_width - barcode_width_max) / 2.0 - x,
                             text_height)
            logo_rect.draw_text_to_fit(pdf, logo,
                                       Rect.AlignLeft | Rect.AlignMiddle)

        if license_code:
            barcode_rect = Rect(margin, page_height - margin * 1.2 + page_y,
                                width, margin * 0.8)
            draw_code128(pdf, license_code, barcode_rect.x, barcode_rect.y,
                         barcode_rect.width, barcode_rect.height)

        if name:
            x = (page_width + barcode_width_max) / 2.0
            name_rect = Rect(x, page_height - margin + page_y,
                             page_width - text_margin - x, text_height)
            name_rect.draw_text_to_fit(pdf, name,
                                       Rect.AlignRight | Rect.AlignMiddle)

    pdf_str = pdf.output(dest='s')
    return pdf_str
Exemplo n.º 15
0
def print_bib_tag_label(participant,
                        sponsor_name=None,
                        left_page=True,
                        right_page=True,
                        barcode=True):
    competition = participant.competition
    license_holder = participant.license_holder

    bib = participant.bib
    name = license_holder.first_last
    if len(name) > 32:
        name = license_holder.first_last_short

    if sponsor_name is None:
        if competition.number_set and competition.number_set.sponsor:
            sponsor_name = competition.number_set.sponsor
        else:
            sponsor_name = competition.name
    system_name = 'CrossMgr'

    # Use points at the units.
    page_width = 3.9 * inches_to_points
    page_height = 2.4 * inches_to_points

    pdf = PDF('L', (page_height, page_width))
    pdf.set_author(RaceDBVersion)
    pdf.set_title('Race Bib Number: {}'.format(bib))
    pdf.set_subject(
        'Bib number and rider info to be printed as a label to apply on the chip tag.'
    )
    pdf.set_creator(getpass.getuser())
    pdf.set_keywords(
        'RaceDB CrossMgr Bicycle Racing Software Database Road Time Trial MTB CycloCross RFID'
    )

    pdf.add_font('din1451alt',
                 style='',
                 fname=get_font_file('din1451alt G.ttf'),
                 uni=True)
    pdf.add_font('Arrows',
                 style='',
                 fname=get_font_file('Arrrows-Regular.ttf'),
                 uni=True)

    margin = min(page_height, page_width) / 18.0
    sep = margin / 2.5

    height = page_height - margin * 2.0
    width = page_width - margin * 2.0

    header = Rect(margin, margin, width, height / 18.0)
    footer = Rect(margin, page_height - margin - header.height, header.width,
                  header.height)
    field = Rect(header.x, header.bottom + sep, width,
                 footer.top - header.bottom - sep * 2)

    license_code = license_holder.uci_id or license_holder.license_code

    leftArrow, rightArrow = 'A', 'a'

    font_name = 'Helvetica'
    for lp in ([True] if left_page else []) + ([False] if right_page else []):
        pdf.add_page()

        arrow = copy.deepcopy(header)
        arrow.y -= arrow.height * 0.5
        arrow.height *= 2
        pdf.set_font('Arrows')
        arrowWidth = arrow.draw_text_to_fit(
            pdf,
            leftArrow if lp else rightArrow,
            (Rect.AlignLeft if lp else Rect.AlignRight) | Rect.AlignMiddle,
            consider_descenders=True,
            convert_to_text=False,
        )
        arrowWidth += pdf.get_string_width('  ')

        header_remain = copy.deepcopy(header)
        if lp:
            header_remain.x += arrowWidth
        header_remain.width -= arrowWidth

        pdf.set_font(font_name)
        header_remain.draw_text_to_fit(
            pdf, sponsor_name,
            (Rect.AlignLeft if lp else Rect.AlignRight) | Rect.AlignMiddle,
            True)

        pdf.set_font('din1451alt', '', 16)
        field.draw_text_to_fit(pdf, bib, Rect.AlignCenter | Rect.AlignMiddle)

        pdf.set_font(font_name)
        name_width = footer.draw_text_to_fit(
            pdf, name,
            (Rect.AlignRight if lp else Rect.AlignLeft) | Rect.AlignMiddle)

        logo = copy.deepcopy(footer)
        if not lp:
            logo.x += name_width + sep
        logo.width -= name_width + sep
        if logo.width > 20:
            logo_width = logo.draw_text_to_fit(
                pdf, system_name,
                (Rect.AlignLeft if lp else Rect.AlignRight) | Rect.AlignMiddle)
        else:
            logo_width = 0

        if barcode:
            remaining_width = header.width - name_width - logo_width
            if lp:
                barcode_rect = Rect(footer.x + logo_width, footer.y,
                                    remaining_width, footer.height)
            else:
                barcode_rect = Rect(
                    footer.right - logo_width - remaining_width, footer.y,
                    remaining_width, footer.height)
            if license_code:
                draw_code128(pdf, license_code, barcode_rect.x, barcode_rect.y,
                             barcode_rect.width, barcode_rect.height)

    pdf_str = pdf.output(dest='s')
    return pdf_str
Exemplo n.º 16
0
# finds path of files

# making an output directory for pdf merged
output_merge = file_path_variable + '/output_merged'
if not os.path.exists(output_merge):
    os.mkdir(output_merge)

for subdir, dirs, files in os.walk(file_path_variable):
    for filename in files:
        filepath = subdir + os.sep + filename
        print(filepath)

        ppt = Ex()

        if filepath.endswith(".ppt"):
            folder = filepath.replace('/', '\\')
            ppt.ppt_convert(folder)

        if filepath.endswith(".pptx"):
            folder = filepath.replace('/', '\\')
            ppt.ppt_convert(folder)

        if filepath.endswith(".pptm"):
            folder = filepath.replace('/', '\\')
            ppt.ppt_convert(folder)

pdf = PDF()
pdf.p(file_path_variable, output_merge.replace('/', '\\'))

root.mainloop()
Exemplo n.º 17
0
from pdf import PDF, Word, Document, Html

#function
def show_common(obj):
    if type(obj) == PDF:
        print(obj.show())
    elif type(obj) == Word:
        print(obj.show())
    elif type(obj) == Html:
        obj.print()
    elif type(obj) == Document:
        print(obj.show())
        # print(obj.name() + ' is an abstract class. Cannot say anything!')

docs = [PDF('Doc1'), Word('Doc2'), Document('Doc3'), Html('Doc4')]
for d in docs:
    # print(d.show())
    show_common(d)
Exemplo n.º 18
0
    def vectorize(self,
                  path,
                  ignore_if_html_file_exists=True,
                  ignore_errors=False,
                  num_threads=1):
        """
		:type path: str or Path
		:type ignore_if_html_file_exists: bool
		:type ignore_errors: bool
		:rtype: DataFrame
		"""
        path = Path(path)
        pdf_paths = [
            PDF(file_path) for file_path in path.list(show_size=False)
            if file_path.extension.lower() == 'pdf'
        ]

        exceptions = []

        # create htmls
        for pdf_path in iterate(iterable=pdf_paths,
                                text='converting pdfs to html'):
            try:
                pdf_path.convert_to_html(
                    ignore_if_exists=ignore_if_html_file_exists)
            except Exception as e:
                if ignore_errors:
                    exceptions.append(e)
                else:
                    raise e

        # get paragraphs
        def extract_paragraphs(pdf_path):
            try:
                pdf_paragraphs = pdf_path.paragraphs
                num_paragraphs = len(pdf_paragraphs)
                return [{
                    'pdf': pdf_path,
                    'paragraph_num': i + 1,
                    'paragraph': paragraph,
                    'num_paragraphs': num_paragraphs
                } for i, paragraph in enumerate(pdf_paragraphs)]

            except Exception as e:
                if ignore_errors:
                    return [{'error': e}]
                else:
                    raise e

        if num_threads == 1:
            paragraph_dict_lists = [
                extract_paragraphs(x) for x in iterate(
                    pdf_paths, text='extracting paragraphs (single-threaded)')
            ]
        else:
            processor = Parallel(n_jobs=num_threads,
                                 backend='threading',
                                 require='sharedmem')
            paragraph_dict_lists = processor(
                delayed(extract_paragraphs)(pdf_path=x) for x in iterate(
                    pdf_paths, text='extracting paragraphs (multi-threaded)'))
        paragraph_dicts = [
            x for paragraph_dict_list in paragraph_dict_lists
            for x in paragraph_dict_list
        ]

        # create vectors
        def get_vector_and_num_tokens(paragraph_dict):
            try:
                pdf_path = paragraph_dict['pdf']
                paragraph_num = paragraph_dict['paragraph_num']
                paragraph = paragraph_dict['paragraph']
                num_paragraphs = paragraph_dict['num_paragraphs']
                vector, num_tokens = self._bert_vectorizer.vectorize(
                    text=paragraph, get_num_tokens=True)
                vector_df = DataFrame(
                    vector,
                    columns=[f'bert_{i + 1}' for i in range(vector.shape[1])])
                vector_df['pdf'] = pdf_path.name_and_extension
                vector_df['num_paragraphs'] = num_paragraphs
                vector_df['paragraph_num'] = paragraph_num
                vector_df['num_tokens'] = num_tokens
                return vector_df
            except Exception as e:
                if ignore_errors:
                    return e
                else:
                    raise e

        if num_threads == 1:
            vectors = [
                get_vector_and_num_tokens(paragraph_dict=x) for x in iterate(
                    paragraph_dicts,
                    text='converting paragraphs to vectors (single-threaded)')
            ]
        else:
            processor = Parallel(n_jobs=num_threads,
                                 backend='threading',
                                 require='sharedmem')
            vectors = processor(
                delayed(get_vector_and_num_tokens)(paragraph_dict=x)
                for x in iterate(
                    paragraph_dicts,
                    text='converting paragraphs to vectors (multi-threaded)'))

        return bring_to_front(
            data=concat(vectors),
            columns=['pdf', 'paragraph_num', 'num_paragraphs',
                     'num_tokens']).reset_index(drop=True)
Exemplo n.º 19
0
        outlines, next_outlines = itertools.tee(outlines, 2)
        next_outlines = itertools.chain(itertools.islice(next_outlines, 1, None), [None])
        return outlines, next_outlines

if __name__ == "__main__":
    import get_pdf
    from test_cases import test_cases
    from get_data import HKEX_API
    from helper import write_to_csv, n_yearsago, today
    # logging.basicConfig(level=logging.INFO)
    # query = HKEX_API(from_date=n_yearsago(n=1), to_date=today())
    
    
    # for data in query.data:
        
    #     result = {}
    #     url = data.file_link
    #     pdf = PDF(url)
    #     print(url)
    #     f = TableOfContent(pdf.pdf_obj)
    #     print()
    #     result['result'] = f.search_outline_page_range(TableOfContent.auditor_remunration_regex)
    #     result['url'] = url
    #     write_to_csv(result, 'result_2.csv')
    
    url = 'https://www1.hkexnews.hk/listedco/listconews/sehk/2020/0813/2020081300777.pdf'
    url = 'https://www1.hkexnews.hk/listedco/listconews/sehk/2020/0813/2020081300670.pdf'
    pdf = PDF(url)
    print(url)
    f = TableOfContent(pdf.pdf_obj)
    print(f.search_outline_page_range(TableOfContent.audit_fee_regex))
Exemplo n.º 20
0
def pdf(request):

    pdf = PDF(request.display_user)

    return pdf.as_response()
Exemplo n.º 21
0
def print_id_label(participant):
    competition = participant.competition
    license_holder = participant.license_holder

    bib = participant.bib
    name = license_holder.first_last
    if len(name) > 32:
        name = license_holder.first_last_short

    system_name = 'CrossMgr'

    inches_to_points = 72.0

    # Use points at the units.
    page_width = 3.9 * inches_to_points
    page_height = 2.4 * inches_to_points

    pdf = PDF('L', (page_height, page_width))
    pdf.set_author(RaceDBVersion)
    pdf.set_title('Bib Number: {}'.format(bib))
    pdf.set_subject('Rider ID and Emergency Information.')
    pdf.set_creator(getpass.getuser())
    pdf.set_keywords(
        'RaceDB CrossMgr Bicycle Racing Software Database Road Time Trial MTB CycloCross'
    )

    margin = min(page_height, page_width) / 18.0
    sep = margin / 2.5

    height = page_height - margin * 2.0
    width = page_width - margin * 2.0

    header = Rect(margin, margin, width, height / 10.0)
    footer_height = height / 20
    footer = Rect(margin, page_height - margin - footer_height, header.width,
                  footer_height)
    field = Rect(header.x, header.bottom + sep, width,
                 footer.top - header.bottom - sep * 2)

    leftArrow, rightArrow = chr(172), chr(174)

    font_name = 'Helvetica'
    pdf.add_page()
    pdf.set_font(font_name, 'b')

    header.draw_text_to_fit(pdf, name, Rect.AlignLeft, True)

    pdf.set_font(font_name)
    info = []
    info.append([
        '',
        u',  '.join([
            u'Age: {}'.format(license_holder.get_age()),
            u'Gender: {}'.format(license_holder.get_gender_display()),
            u'Nation: {}'.format(license_holder.nation_code),
        ]),
    ])
    info.append(['', ''])
    if participant.team:
        info.append(['', u'{}'.format(participant.team.name)])
    info.append([
        '',
        u',  '.join([
            u'Bib: {}'.format(participant.bib),
            u'Category: {}'.format(participant.category.code_gender
                                   if participant.category else ''),
        ]),
    ])
    if license_holder.phone:
        info.append([
            '',
            u'  '.join([
                u'Phone: {}'.format(format_phone(license_holder.phone)),
            ]),
        ])

    info.append(['', ''])
    if license_holder.emergency_medical:
        info.append([
            '', u'Medical Alert: {}'.format(license_holder.emergency_medical)
        ])
    info.append(['', u'Emergency Contact:'])
    if license_holder.emergency_contact_name:
        info.append([
            '', u'  {}'.format(license_holder.emergency_contact_name
                               or 'None provided')
        ])
    info.append([
        '', u'  {}'.format(
            format_phone(license_holder.emergency_contact_phone)
            or 'No phone number provided')
    ])

    pdf.table_in_rectangle(field.x,
                           field.y,
                           field.width,
                           field.height,
                           info,
                           leftJustifyCols=[0, 1],
                           hasHeader=False,
                           horizontalLines=False)

    footer.draw_text_to_fit(pdf, system_name, Rect.AlignRight, True)

    pdf_str = pdf.output(dest='s')
    return pdf_str
Exemplo n.º 22
0
 def __init__(self, font='JetBrainsMono'):
     self.pdf = PDF(font)
     self.errors = []