简体   繁体   English

python fpdf 在单元格中添加图像

[英]python fpdf add an image in cell

I am generating a PDF file using FPDF in Python. Below is a code snippet, where I am creating a table using cell.我在 Python 中使用 FPDF 生成一个 PDF 文件。下面是一个代码片段,我在其中使用单元格创建一个表。 The table consists of 3 columns.该表由 3 列组成。 In the last cell of each row, I need to insert an image with a QR code.在每一行的最后一个单元格中,我需要插入一个带有二维码的图像。 I don't know how to insert an image inside a cell.我不知道如何在单元格中插入图像。

#Create table header
height = 5
pdf.cell(w = 50, h = height, txt = 'Product', align = 'L', border = 'B', ln = 0)
pdf.cell(w = 120, h = height, txt = 'Instructioon', align = 'L', border = 'B', ln = 0)
pdf.cell(w = 20, h = height, txt = 'Video', align = 'L', border = 'B', ln = 1)
#Create the content in the first table row
pdf.cell(w = 50, h = height, txt = 'Product 1', align = 'L', ln = 0)
pdf.cell(w = 120, h = height, txt = 'some product descriptions', align = 'L', ln = 0)
#This is the cell I need to insert an image with a QR code, but I don't know how to insert the image inside a cell
pdf.cell(....)

Here is a workaround.这是一个解决方法。 Instead of creating the PDF directly with FPDF with limited functionality, you can create an HTML file, populate it with data, take a screen shot, and finally create a PDF.您可以创建一个 HTML 文件,用数据填充它,截屏,最后创建一个 PDF,而不是直接使用功能有限的 FPDF 创建 PDF。

See this Medium Article for reference: https://betterprogramming.pub/generating-stunning-pdf-reports-with-aws-and-python-a47274afe03d请参阅这篇中篇文章以供参考: https://betterprogramming.pub/generating-stunning-pdf-reports-with-aws-and-python-a47274afe03d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM