无法在 PDF 文件中写入图像

Unable to write image in PDF File

def logo_para(self):
    exp = Paragraph(
        '<b>Express</b>', self.styles['CenterHeading'])
    csheet = Paragraph(
        '<b>PDF SHEET</b>', self.styles['CenterHeading'])

    img_location = "https://www.google.co.in/logos/doodles/2016/icc-australia-v-bangladesh-5759441086447616-res.png"

    img_data = '''
       <para><img src="%s" width="300" height="90"/><br/>
       </para>''' % img_location
    img = Paragraph(img_data, self.styles['CenterHeading'])
    data = [[exp], [csheet], [''], [img] ]
    main_header_table = Table([['', img, '']], colWidths=(100, 300, 100))
    main_header_table.setStyle(TableStyle([
        ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
        ('BOX', (0, 0), (-1, -1), 0.25, colors.black)
    ]))
    self.elements.append(main_header_table)

每当我打电话时

docket.logo_para()

我在 self.doc.build(self.elements)

收到错误 cannot concatenate 'str' and 'int' objects

注释该行时docket.logo_para(),代码运行得非常好。

我正在尝试使用 SimpleDocTemplate

在 PDF 文件中添加图像

编辑 1

正在创建新的 pdf

class PDFDocketGenerator(object):
def __init__(self, file_name):
    self.filename = file_name
    self.filepath = STATIC_URL + 'uploads/billing/' + file_name
    self.path_to_save = FILE_UPLOAD_TEMP_DIR + '/billing/' + file_name
    # define the pdf object
    self.doc =  SimpleDocTemplate(
        self.path_to_save, pagesize=landscape(A4), topMargin=50, bottomMargin=30,
        leftMargin=60, rightMargin=60)
    self.elements = []

写入 pdf

 def write_pdf(self):

        self.doc.build(self.elements)

有没有可能self.elements中的某些值是整数?我建议在这种情况下试试这个:

def write_pdf(self):

    self.doc.build([str(e) for e in self.elements])