我正在尝试将不同的照片输出到不同的 pdf 中,但我看到它仍在所有 pdf 中打印同一张照片。
namelist=[]
值是['ABC1 XYZ1', 'ABC2 XYZ2', 'ABC3 XYZ3', 'ABC4 XYZ4', 'ABC5 XYZ5']
与名称列表中命名相同的图片,
但它仍然只输出第一张图片。为什么?
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,2000/50,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')