2023-04-22

AttributeError: 'NumberObject' object has no attribute 'indirect_reference'

I've been trying to create multiple pdfs and merge them using pypdf (Version 3.7.1). The static data such as images and fonts render out perfectly within the html but don't in pdfs. Following is my code and the error I'm encountering

query_set = booklet.objects.filter(booklet_id = id)

combine = []

for i in query_set:
    size = i.size
    
    options = {
        'page-size': f'{size}',
        'orientation': 'Landscape' if i.template_mode == "2" else "Portrait",
        'margin-top': '0mm',
        'margin-right': '0mm',
        'margin-bottom': '0mm',
        'margin-left': '0mm',
        'encoding': "UTF-8",
        'dpi': 900
    }

    url = f"http://ipaddress/test?ids={get_ids}&uuid={i.uuid}&size={i.size}&mode={i.mode}&type_set={i.te_type}&template={i.name}&pre{id.id}"

    pdfkit.from_url(url, output_path=f"{file_path}/pdfs/{i.te_type}_{i.name}_{i.id}_.pdf", options=options, verbose=False)
    combine.append(f"{file_path}/pdfs/{i.te_type}_{i.name}_{i.id}_.pdf")

merger = PdfWriter()

for pdfs in combine:
    merger.append(pdfs)
    pdf_name = "base.pdf"
    merger.write(pdf_name)
    merger.close()

return JsonResponse({"pdf" : pdf_name"})

I have tried cnfiguring the nginx file, thinking it could be the case but it is not

I have tried modifying my code and relocating static folder to no success.

I have tried rendering static images into a separate template but as i mentioned above they render in just fine but not in the pdf generated by pypdf



No comments:

Post a Comment