因此,我弄清楚了如何使用PyMuPDF将条形码图像插入到PDF中。现在,我需要做的是在PDF的每一页上放置不同的图像。到目前为止,我的代码是:
input_file = "PDF_File"
output_file = "example-with-barcode.pdf"
# define the position of the image
rect = fitz.Rect(0, 370, 400, 400)
# supported image file
pix = fitz.Pixmap("barcodeimage.jpg")
# existing PDF
doc = fitz.open(input_file)
# retrieve the first page of the PDF
page = doc[0]
# add the image
page.insertImage(rect, pixmap=pix, keep_proportion=True, overlay=True)
# save your work
doc.save(output_file)
我想要做的就是将其转换为一个函数,该函数根据文件所在的目录位置为条形码图像获取多个参数。我该怎么做?预先感谢。