当前位置: 首页>>代码示例>>Python>>正文


Python fpdf.FPDF属性代码示例

本文整理汇总了Python中fpdf.FPDF属性的典型用法代码示例。如果您正苦于以下问题:Python fpdf.FPDF属性的具体用法?Python fpdf.FPDF怎么用?Python fpdf.FPDF使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在fpdf的用法示例。


在下文中一共展示了fpdf.FPDF属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_font

# 需要导入模块: import fpdf [as 别名]
# 或者: from fpdf import FPDF [as 别名]
def set_font(self, family, style='', size=0, underline=False):
        font = self.available_fonts.get(family)
        if font:
            if not font['standard_font']:
                # get font for specific style
                if style:
                    # replace of 'U' is needed because it is set for underlined text
                    # when called from FPDF.add_page
                    style_font = font['style' + style.replace('U', '')]
                    # style could be different in case styles are mapped,
                    # e.g. if bold style has same font file as regular style
                    style = style_font['style']
                else:
                    style_font = font['style']

                if not style_font['font_added']:
                    self.add_font(
                        family, style=style, fname=style_font['font_filename'], uni=font['uni'])
                    style_font['font_added'] = True

            if underline:
                style += 'U'
            fpdf.FPDF.set_font(self, family, style, size) 
开发者ID:jobsta,项目名称:reportbro-lib,代码行数:25,代码来源:reportbro.py

示例2: write_pdf

# 需要导入模块: import fpdf [as 别名]
# 或者: from fpdf import FPDF [as 别名]
def write_pdf(self):
        # Write PDF.
        from fpdf import FPDF
        from PIL import Image
        dpi = 120 # note for calcs below that "pt" units are 1/72th of an inch
        pdf = FPDF(unit="pt")
        for image in self.screenshot_image_filenames:
            # Size the next PDF page to the size of this image.
            with open(image, "rb") as f:
                im = Image.open(f)
                page_size = im.size[0]/dpi*72, im.size[1]/dpi*72
            pdf.add_page(format=page_size)
            pdf.image(image, 0,0, page_size[0], page_size[1])
        pdf.output(self.write_pdf_filename, "F")

        # Delete the temporary directory of images.
        import shutil
        shutil.rmtree(self.screenshot_basepath)


    # SCRIPT UTILITY FUNCTIONS 
开发者ID:GovReady,项目名称:govready-q,代码行数:23,代码来源:test_screenshots.py

示例3: pdf_save

# 需要导入模块: import fpdf [as 别名]
# 或者: from fpdf import FPDF [as 别名]
def pdf_save(data_movies,headers):
    pdf = fpdf.FPDF(format='letter')
    pdf.add_page()
    pdf.set_font("Arial", size=12)
    pdf.cell(200, 10, txt="Tv Timings !",ln=1, align="C")
    for data in data_movies:
        str1 = "Movie: " + str(data[0]) + "  Time: " + str(data[1])+ "  Rating: " + str(data[2])
        pdf.cell(200, 10, str1,0,1, align="l")
    pdf.output('La-Z-Boy.pdf') 
开发者ID:madan96,项目名称:La-Z-Boy,代码行数:11,代码来源:__main__.py

示例4: randompdf

# 需要导入模块: import fpdf [as 别名]
# 或者: from fpdf import FPDF [as 别名]
def randompdf (path) :

	numpdf = (randint(1500,2000))

	for i in range(10):
	
		name = path + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(randint(5,15))]) + ".pdf"
	
		numwords = (randint(200,1000))
	
		pdf = FPDF()
		pdf.add_page()
		pdf.set_font("Arial", size=12)
	
		words =[]
	
		for i in range(numwords):
		
			randomword  = ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(randint(5,15))])
			words.append(randomword)
	
		wordsinstring = ''.join(words)
	
		pdf.cell(200, 10, txt=wordsinstring, align="C")
		
		pdf.output(name)
		
		for i in range(numpdf):
			
			dupli = path + ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(randint(5,15))]) + ".pdf"
			
			copyfile(name, dupli) 
开发者ID:YJesus,项目名称:AntiRansom,代码行数:34,代码来源:generator.py

示例5: createPDF

# 需要导入模块: import fpdf [as 别名]
# 或者: from fpdf import FPDF [as 别名]
def createPDF(self, name=None, size='10kb'):
        from PyPDF2 import PdfFileReader, PdfFileWriter
        from fpdf import FPDF
        import os
        import random
        name = os.path.basename(name)
        tmp_name = '/tmp/' + name
        output_name = self.sharepath + '/' + name

        if size == '10kb':
            randlength = random.randint(10000,90000)
        elif size == '100kb':
            randlength = random.randint(100000,900000)
        elif size == '1mb':
            randlength = random.randint(1000000,9000000)

        #create file
        pdf=FPDF()
        pdf.add_page()
        pdf.set_font('Arial','B',8)
        pdf.cell(0,0,os.urandom(randlength))
        pdf.output(tmp_name, "F")

        #encrypt it
        output = PdfFileWriter()
        input1 = PdfFileReader(open(tmp_name, "rb"))
        output.encrypt(user_pwd="ihasapass")
        output.addPage(input1.getPage(0))

        outputStream = file(output_name, "wb")
        output.write(outputStream)
        outputStream.close() 
开发者ID:thinkst,项目名称:opencanary,代码行数:34,代码来源:testpdf.py

示例6: create_summary_brief

# 需要导入模块: import fpdf [as 别名]
# 或者: from fpdf import FPDF [as 别名]
def create_summary_brief(summary, temp_file):
    '''
    Write a PDF page with the summary information, in the specified temp_file
    '''
    document = fpdf.FPDF()
    document.set_font('Times', '', 12)
    document.add_page()
    TEMPLATE = '''
    Report generated at {now}
    Covering data from {start_time} to {end_time}


    Summary
    -------
    TOTAL INCOME: $ {income}
    TOTAL UNIT: {units} units
    AVERAGE DISCOUNT: {discount}%
    '''

    def format_full_tmp(timestamp):
        return timestamp.datetime.isoformat()

    def format_brief_tmp(timestamp):
        return timestamp.datetime.strftime('%d %b')

    text = TEMPLATE.format(now=format_full_tmp(delorean.utcnow()),
                           start_time=format_brief_tmp(summary['start_time']),
                           end_time=format_brief_tmp(summary['end_time']),
                           income=summary['total_income'],
                           units=summary['units'],
                           discount=summary['average_discount'])

    document.multi_cell(0, 6, text)
    document.ln()
    document.output(temp_file)
    return temp_file 
开发者ID:PacktPublishing,项目名称:Python-Automation-Cookbook,代码行数:38,代码来源:generate_sales_report.py

示例7: generate_pdf

# 需要导入模块: import fpdf [as 别名]
# 或者: from fpdf import FPDF [as 别名]
def generate_pdf(id, message):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font('Arial', 'B', 16)
    pdf.cell(40, 10, message)
    pdf.output(str(id) + '.pdf', 'F') 
开发者ID:blabla1337,项目名称:skf-labs,代码行数:8,代码来源:IDOR.py

示例8: __init__

# 需要导入模块: import fpdf [as 别名]
# 或者: from fpdf import FPDF [as 别名]
def __init__(self, infile=None, elements=None, format='A4', orientation='portrait',
                 title='', author='', subject='', creator='', keywords=''):
        if elements:
            self.elements = elements
            self.keys = [v['name'].lower() for v in self.elements]
        self.handlers = {'T': self.text, 'L': self.line, 'I': self.image, 
                         'B': self.rect, 'BC': self.barcode, }
        self.pg_no = 0
        self.texts = {}
        pdf = self.pdf = FPDF(format=format,orientation=orientation, unit="mm")
        pdf.set_title(title)
        pdf.set_author(author)
        pdf.set_creator(creator)
        pdf.set_subject(subject)
        pdf.set_keywords(keywords) 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:17,代码来源:template.py

示例9: __init__

# 需要导入模块: import fpdf [as 别名]
# 或者: from fpdf import FPDF [as 别名]
def __init__(self, document_properties, additional_fonts):
        if document_properties.orientation == Orientation.portrait:
            orientation = 'P'
            dimension = (document_properties.page_width, document_properties.page_height)
        else:
            orientation = 'L'
            dimension = (document_properties.page_height, document_properties.page_width)
        fpdf.FPDF.__init__(self, orientation=orientation, unit='pt', format=dimension)
        self.x = 0
        self.y = 0
        self.set_doc_option('core_fonts_encoding', 'windows-1252')
        self.loaded_images = dict()
        self.available_fonts = dict(
            courier=dict(standard_font=True),
            helvetica=dict(standard_font=True),
            times=dict(standard_font=True))
        if additional_fonts:
            for additional_font in additional_fonts:
                filename = additional_font.get('filename', '')
                font = dict(
                    standard_font=False, uni=additional_font.get('uni', True))

                regular_style = dict(
                    font_filename=filename, style='', font_added=False)
                bold_style = dict(
                    font_filename=additional_font.get('bold_filename', filename),
                    style='B', font_added=False)
                italic_style = dict(
                    font_filename=additional_font.get('italic_filename', filename),
                    style='I', font_added=False)
                bold_italic_style = dict(
                    font_filename=additional_font.get('bold_italic_filename', filename),
                    style='BI', font_added=False)

                # map styles in case there are no separate font-files for bold, italic or bold italic
                # to avoid adding the same font multiple times to the pdf document
                if bold_style['font_filename'] == regular_style['font_filename']:
                    bold_style = regular_style
                if italic_style['font_filename'] == regular_style['font_filename']:
                    italic_style = regular_style
                if bold_italic_style['font_filename'] == italic_style['font_filename']:
                    bold_italic_style = italic_style
                elif bold_italic_style['font_filename'] == bold_style['font_filename']:
                    bold_italic_style = bold_style
                elif bold_italic_style['font_filename'] == regular_style['font_filename']:
                    bold_italic_style = regular_style
                font['style'] = regular_style
                font['styleB'] = bold_style
                font['styleI'] = italic_style
                font['styleBI'] = bold_italic_style

                self.available_fonts[additional_font.get('value', '')] = font 
开发者ID:jobsta,项目名称:reportbro-lib,代码行数:54,代码来源:reportbro.py


注:本文中的fpdf.FPDF属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。