Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Debug please
#11
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

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')
Reply
#12
Hello,

I've tried the multi cell command and its saying that the set x and y commands are not objects inside FPDF.

Maybe my version is out of date?

Cheers,
Jamie
while dad_has_cigs == True:
    happiness = True
    if dad_has_cigs == False:
    print("Dad come home!")
    happiness = not happiness
    break
Reply
#13
That's weird, the above works well for me.

You can get the version on Linux with:

Quote:pedro@pedro-HP:~$ pip freeze | grep fpdf
fpdf==1.7.2
pedro@pedro-HP:~$

and Python

Quote:pedro@pedro-HP:~$ python3 --version
Python 3.8.10
pedro@pedro-HP:~$

Attached Files

Thumbnail(s)
   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pycharm debug help mg24 1 996 Nov-18-2022, 05:38 AM
Last Post: deanhystad
  Python debug suddenly got bad ben1122 3 1,062 Sep-03-2022, 06:20 AM
Last Post: ben1122
  Error in Int object is not subscript-able. How to debug this ? yanDvator 1 2,195 Aug-03-2020, 02:28 PM
Last Post: Larz60+
  is there a debug mode available while creating python egg BhushanPathak 1 2,341 Dec-19-2018, 04:15 PM
Last Post: Larz60+
  Help debug my fibonacci implementation dineshpabbi10 6 3,921 May-16-2018, 12:12 PM
Last Post: dineshpabbi10
  Not sure how to debug this? rsmldmv 3 5,406 Nov-09-2017, 02:51 AM
Last Post: snippsat
  Debug and trace in python quocchi22101262 0 3,463 Jun-20-2017, 09:35 AM
Last Post: quocchi22101262

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020