fpdf set margin to page not working in python

Viewed 277

i try to make margin for my page but nothing work, my script create image between 0 margin but when i print it, the margin image are cut into margin page (im bad in english, sorry) i would like create margin page at left,top,right,bottom of 5mm thank for your help

 class MyFPDF(FPDF):
         pass

    def photos_pdf():
         pdf = MyFPDF("P", format='A3', unit='mm')
         photos = glob.glob(filePath1 + "/*.png")
         x = 0
         y = 0
         counter = 0
         nbre = 5
         nbre_par_page = 15
         counter2 = 0
         
         pdf.add_page()
         MyFPDF.set_left_margin(32)
         MyFPDF.set_right_margin(32)

         for photo in photos:
            if counter2 != nbre_par_page:    
                if counter != (nbre):
                   
                    pdf.image(photo, x=x, y=y, w=63, h=88)
                    x += 63
                    counter += 1
                    counter2 += 1
                
                else:
                    
                    pdf.image(photo, x=x, y=y, w=63, h=88)
                    y += 88
                    x = 0
                    counter = 0
                    
            else:
                
                pdf.image(photo, x=x, y=y, w=63, h=88) 
                pdf.add_page()
                
                
                counter = 0
                counter2 = 0
                
                x = 0
                y = 0
           
       
         pdf.output(path2 + "/A4_cards.pdf", 'F')
         os.chmod(path2 + "/A4_cards.pdf", 0o777)
    photos_pdf()  

could you help me

1 Answers

Try setting your margins before you use add_page(). Also, use your pdf object to call the methods rather than MyFPDF.

Related