Search code examples
pythonreportlab

reportlab TypeError: drawImage() takes at least 4 arguments (5 given)


I'm trying to create a report using reportlab in python.

Here are the relevant lines before the problem:

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.pagesizes import landscape

c = canvas.Canvas(pdf_file_name, pagesize=landscape(letter))

here is line 53 from my python script:

c.drawImage(350, 50, width=None,height=None)

I get the following error:

Traceback (most recent call last):
File "report_test.py", line 59, in <module>
import_data(data_file)
File "report_test.py", line 29, in import_data
generate_certificate(email, agent_id, pdf_file_name)
File "report_test.py", line 53, in generate_certificate
c.drawImage(350, 50, width=None,height=None)
TypeError: drawImage() takes at least 4 arguments (5 given)

I only see 4 arguments given. What am I missing?


Solution

  • The first parameter passed to any instance method is the instance itself, known by convention as self. In this case, the Canvas object c is being passed as the first argument. This, plus the four arguments you are explicitly passing, makes five.

    Still, it seems that five is more than four, and it says it wants at least four, right? So what's the dilemma, Emma? It appears that this error message is erroneous (i.e., a bug). What it's probably really complaining about is that you have not specified the image to be drawn. This (a filename or an ImageReader object) should be the first parameter.