Python fpdf.FPDF Examples
The following are 9
code examples of fpdf.FPDF().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
fpdf
, or try the search function
.

Example #1
Source File: reportbro.py From reportbro-lib with GNU Affero General Public License v3.0 | 7 votes |
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)
Example #2
Source File: test_screenshots.py From govready-q with GNU General Public License v3.0 | 7 votes |
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
Example #3
Source File: __main__.py From La-Z-Boy with MIT License | 6 votes |
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')
Example #4
Source File: generator.py From AntiRansom with GNU General Public License v2.0 | 6 votes |
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)
Example #5
Source File: testpdf.py From opencanary with BSD 3-Clause "New" or "Revised" License | 6 votes |
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()
Example #6
Source File: generate_sales_report.py From Python-Automation-Cookbook with MIT License | 6 votes |
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
Example #7
Source File: IDOR.py From skf-labs with GNU Affero General Public License v3.0 | 6 votes |
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')
Example #8
Source File: template.py From termite-visualizations with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #9
Source File: reportbro.py From reportbro-lib with GNU Affero General Public License v3.0 | 5 votes |
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