pdf.image 图像在for循环中打印图像相同的图像

问题描述

我正在尝试将不同的照片输出为不同的 pdf 但我看到它仍然在所有 pdf 中打印相同的照片。

namelist=[] 值为 ['ABC1 XYZ1','ABC2 XYZ2','ABC3 XYZ3','ABC4 XYZ4','ABC5 XYZ5'] pics named same as in namelist 但它仍然只输出第一张图像。为什么? ABC2 XYZ2.pdf 请参阅 ABC2 XYZ2.pdf 中的此处。它应该输出 ABC2 XYZ2.jpg 图像。

from fpdf import FPDF
from main import *
import os
class PDF(FPDF):
    def lines(self):
        self.set_fill_color(255,99,71) # color for outer rectangle
        self.rect(5.0,5.0,200.0,287.0,'DF')
        self.set_fill_color(255,255,255) # color for inner rectangle
        self.rect(8.0,8.0,194.0,281.0,'FD')
    
    def imagex(self,sctplt,x,y,width,height):
        self.set_xy(x,y)
        self.image(sctplt,type='',w=width,h=height)
    def titles(self):
        self.set_xy(0.0,0.0)
        self.set_font('Arial','B',16)
        self.set_text_color(220,50,50)
        self.cell(w=210.0,h=40.0,align='C',txt="t",border=0)
    def texts(self,name):
        with open(name,'rb') as xy:
            txt=xy.read().decode('latin-1')
        self.set_xy(10.0,80.0)    
        self.set_text_color(76.0,32.0,250.0)
        self.set_font('Arial','',12)
        self.multi_cell(0,10,txt)
        

namelist=[]
for k in range(len(x)):
    namelist.append(x[k][0])
print(namelist)

pdf = PDF(orientation='P',unit='mm',format='A4')
pdf.add_page()
pdf.lines()
image1="wisdom test/1.png"
image2="wisdom test/2.png"
pdf.imagex(image1,89.0,10.0,2000/50,1920/50)
pdf.imagex(image2,20.0,50.0,1920/50)

for i in range(len(namelist)):
    currstudent=namelist[i]
    pdf.imagex("pics/{}.jpg".format(currstudent),22.0,52.5,1900/60,1850/55)
    pdf.output('{}.pdf'.format(currstudent),'F')
        
    
    pdf.titles()
    pdf.output('{}.pdf'.format(currstudent),'F')

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)