3

I am generating a PDF file using FPDF in Python. Below is a code snippet, where I am creating a table using cell. The table consists of 3 columns. 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(....)
jxw
  • 586
  • 2
  • 6
  • 36

2 Answers2

1

I add a link reference

pdf.cell(col_width, line_height*3, border=1,align='L', link=pdf.image('my_image.png', 10, 8, 25))

https://pyfpdf.github.io/fpdf2/Tables.html

Luster
  • 11
  • 2
-1

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.

See this Medium Article for reference: https://betterprogramming.pub/generating-stunning-pdf-reports-with-aws-and-python-a47274afe03d

tripleee
  • 175,061
  • 34
  • 275
  • 318