def dotest(outputname, nostamp=True): pdf = FPDF(unit="pt") pdf._putinfo = lambda: common.test_putinfo(pdf) pdf.add_page() pdf.set_font("Times", size=12) pdf.cell(0, 12, "Dummy content") # Get the PDF data the usual way via a real file pdf.output(outputname) with open(outputname, "rb") as file: data = file.read(1000) assert len(data) == 966, "Unexpected PDF file size" try: # Python < 3 (Python 2.5 does not have the "io" module) from cStringIO import StringIO capture = StringIO() detach = lambda: capture except ImportError: # Python >= 3.1 from io import TextIOWrapper, BytesIO # Ensure that no text encoding is actually done capture = TextIOWrapper(BytesIO(), "undefined") detach = lambda: capture.detach() # Compare data when output() writes to stdout original_stdout = sys.stdout try: sys.stdout = capture pdf.output() capture = detach() finally: sys.stdout = original_stdout assert capture.getvalue() == data, "Unexpected stdout data" # Compare data when output() returns a byte string returned = pdf.output(dest="S") assert isinstance(returned, bytes), "output() should return bytes" assert returned == data, "Unexpected PDF data returned"
def dotest(outputname, nostamp): try: # Portrait, millimeter units, A4 page size pdf = FPDF("P", "mm", "A4") # Set font: Times, normal, size 10 pdf.set_font('Times','', 12) ##pdf.add_page() # Layout cell: 0 x 5 mm, text, no border, Left pdf.cell(0,5,'Input 1 : ',border=0,align="L") pdf.cell(0,5,'Input 2 : ', border=0,align="L") pdf.cell(0,5,'Recomendation : ', border=0, align="L") pdf.cell(0,5,'Data 1 :', border=0, align="L" ) pdf.cell(0,5,'Data 2 :', border=0, align="L" ) pdf.output(outputname,'F') except RuntimeError as e: assert e.args[0] == "FPDF error: No page open, you need to call add_page() first" else: raise RuntimeError("Exception not raised!")
from gaefpdf import FPDF pdf = FPDF() pdf.add_page() pdf.set_font('Arial', 'B', 16) pdf.cell(40, 10, 'Hello World!') pdf.output('tuto1.pdf', 'F')
# -*- coding: iso-8859-1 -*- import os from gaefpdf import FPDF pdf = FPDF() pdf.add_page() pdf.set_font('helvetica', '', 13.0) pdf.set_xy(105.0, 8.0) pdf.cell(ln=0, h=22.0, align='C', w=75.0, txt='Sample Invoice', border=0) pdf.set_line_width(0.0) pdf.rect(15.0, 15.0, 170.0, 245.0) pdf.set_line_width(0.0) pdf.rect(95.0, 15.0, 10.0, 10.0) pdf.image('../tutorial/logo.png', 20.0, 17.0, link='', type='', w=13.0, h=13.0) pdf.set_font('arial', 'B', 16.0) pdf.set_xy(95.0, 18.0) pdf.cell(ln=0, h=2.0, align='C', w=10.0, txt='X', border=0) pdf.set_font('arial', '', 8.0) pdf.set_xy(105.0, 21.0) pdf.cell(ln=0, h=4.0, align='C', w=75.0, txt='Original', border=0) pdf.set_font('arial', 'B', 7.0) pdf.set_xy(95.0, 21.5) pdf.cell(ln=0, h=4.5, align='C', w=10.0, txt='COD.00', border=0) pdf.set_line_width(0.0) pdf.line(100.0, 25.0, 100.0, 57.0) pdf.set_font('arial', 'B', 14.0) pdf.set_xy(125.0, 25.5) pdf.cell(ln=0, h=9.5, align='L', w=60.0, txt='00000001', border=0) pdf.set_xy(115.0, 27.5) pdf.cell(ln=0, h=5.5, align='L', w=10.0, txt='N\xba: ', border=0)