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


Messages In This Thread
Help Debug please - by jamesaarr - Jul-26-2021, 09:11 AM
RE: Help Debug please - by deanhystad - Jul-26-2021, 12:18 PM
RE: Help Debug please - by jamesaarr - Jul-26-2021, 12:38 PM
RE: Help Debug please - by deanhystad - Jul-26-2021, 02:34 PM
RE: Help Debug please - by jamesaarr - Jul-27-2021, 08:54 AM
RE: Help Debug please - by Pedroski55 - Jul-27-2021, 08:57 AM
RE: Help Debug please - by jamesaarr - Jul-27-2021, 09:15 AM
RE: Help Debug please - by jamesaarr - Jul-27-2021, 09:38 AM
RE: Help Debug please - by jamesaarr - Jul-27-2021, 09:58 AM
RE: Help Debug please - by Pedroski55 - Jul-27-2021, 11:20 AM
RE: Help Debug please - by Pedroski55 - Jul-28-2021, 02:52 AM
RE: Help Debug please - by jamesaarr - Jul-28-2021, 10:41 AM
RE: Help Debug please - by Pedroski55 - Jul-28-2021, 11:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  no debug messages going into log file robertkwild 0 626 Jul-09-2024, 05:30 PM
Last Post: robertkwild
  pycharm debug help mg24 1 1,852 Nov-18-2022, 05:38 AM
Last Post: deanhystad
  Python debug suddenly got bad ben1122 3 1,966 Sep-03-2022, 06:20 AM
Last Post: ben1122
  Error in Int object is not subscript-able. How to debug this ? yanDvator 1 2,897 Aug-03-2020, 02:28 PM
Last Post: Larz60+
  is there a debug mode available while creating python egg BhushanPathak 1 3,176 Dec-19-2018, 04:15 PM
Last Post: Larz60+
  Help debug my fibonacci implementation dineshpabbi10 6 5,435 May-16-2018, 12:12 PM
Last Post: dineshpabbi10
  Not sure how to debug this? rsmldmv 3 6,474 Nov-09-2017, 02:51 AM
Last Post: snippsat
  Debug and trace in python quocchi22101262 0 3,989 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