import weasyprint
def admin_order_pdf(request, sell_id): # working fine
try:
sell = Sell.objects.get(id=sell_id)
except Sell.DoesNotExist:
return HttpResponse(‘Sell object does not exist’)html = render_to_string(‘sell_invoice.html’, {‘sell’: sell})
response = HttpResponse(content_type=’application/pdf’)app_static_dir = os.path.join(settings.BASE_DIR, ‘pdf’, ‘static’)
css_path = os.path.join(app_static_dir, ‘css’, ‘css.css’)
response[‘Content-Disposition’] = f’filename=sell_{sell.id}.pdf’
weasyprint.HTML(string=html).write_pdf(response, stylesheets=[weasyprint.CSS(css_path)])
return response
With the code, I can easily generate a PDF.
I can design with inline CSS and. CSS files on my PDF, but I can’t pass any photos or pictures.Is it possible to add picture on a PDF ?if yes,? How can I pass a picture/logo on my PDF?