【问题标题】:fpdf set margin to page not working in pythonfpdf设置页边距在python中不起作用
【发布时间】:2021-12-20 13:58:46
【问题描述】:

我尝试为我的页面设置边距,但没有任何效果,我的脚本在 0 边距之间创建图像,但是当我打印它时,边距图像被切入边距页面(我的英文不好,抱歉) 我想在 5mm 的左、上、右、下创建边距页 感谢您的帮助

 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()  

你能帮我吗

【问题讨论】:

    标签: python set margin fpdf


    【解决方案1】:

    在使用add_page() 之前尝试设置边距。此外,使用您的 pdf 对象而不是 MyFPDF 来调用方法。

    【讨论】:

      猜你喜欢
      • 2021-06-08
      • 2012-09-16
      • 1970-01-01
      • 1970-01-01
      • 2013-09-02
      • 2016-02-20
      • 2018-11-30
      • 2018-03-23
      • 1970-01-01
      相关资源
      最近更新 更多