Jul-28-2021, 02:52 AM
(This post was last modified: Jul-28-2021, 02:52 AM by Pedroski55.)
Hi again!
You should read the docs here and look online for examples.
I would not enter the address by hand, save addresses in a database and read them in from there, using a customer number.
Your problem, I think, is positioning the cells on the page. I would use absolute positioning.
In the code below, just play with the x and y values and the cell width and height to get the "labels" exactly where you want them.
FPDF uses A4 size pages and millimetres, unless otherwise directed
I tried this in Idle and get the results I want.
It was interesting to see FPDF at work! Hope it helps, but I think I will stick with reportlab!
A cell won't accept line breaks, so I changed to multi_cell
You should read the docs here and look online for examples.
I would not enter the address by hand, save addresses in a database and read them in from there, using a customer number.
Your problem, I think, is positioning the cells on the page. I would use absolute positioning.
In the code below, just play with the x and y values and the cell width and height to get the "labels" exactly where you want them.
FPDF uses A4 size pages and millimetres, unless otherwise directed
I tried this in Idle and get the results I want.
It was interesting to see FPDF at work! Hope it helps, but I think I will stick with reportlab!
A cell won't accept line breaks, so I changed to multi_cell
Quote:>>> myfile = openPDF()
>>> labels = myPDF(myfile)
>>> labels.output(path + 'tuto1.pdf', 'F')
''
from fpdf import FPDF # quickly make a pdf for test purposes in the Idle shell # later put this directly in the myPDF() function def openPDF(): pdf = FPDF() pdf.set_fill_color(200,200,100) pdf.add_page() pdf.set_font('Arial', 'B', 16) return pdf # take the pdf created and put cells at the required positions def myPDF(mypdf): # by playing with x and y you can position your "labels" exactly where you want them for y in range(50, 250, 50): # first x value x_value = 10 # this sets the position of the top left corner of the cell, I believe mypdf.set_xy(x_value, y) # now draw the cell at this position # change cell size to suit mypdf.multi_cell(40, 10, 'Hello World!', align='L', border=1, fill=True) # increase x and draw the cell again # the increase must be bigger than the width of the first cell, or the cells will be adjoining x_value = 70 # this sets the position of the top left corner of the cell mypdf.set_xy(x_value, y) # now draw the cell at this position # change cell size to suit mypdf.multi_cell(40, 10, 'Hello World!', align='L', border=1, fill=True) return mypdf path = '/home/pedro/pdfs/' myfile = openPDF() labels = myPDF(myfile) labels.output(path + 'tuto1.pdf', 'F')