當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。