Failure to generate a pdf

Hello all!

I am still new to ERPNext; I use v15, and I tried creating my own print format.
I have 2 doctypes:

  1. Property
  2. Agent

and I added a custom HTML field to refer to my Agent module:

{% set agent = frappe.get_doc('Agent', doc.agent) %}
<img src='{{ agent.image }}' height="200px" width="200px">

So in the normal print render it works and pops on the screen, but when I try to generate a PDF, it gives the following:

frappe.exceptions.PrintFormatError: Error in print format on line 19: Agent None not found

Try with the following syntax:

{% set cus_address_id = doc.customer_address %}
{% set cus_add = frappe.get_doc(‘Address’, cus_address_id) if cus_address_id and frappe.db.exists(‘Address’, cus_address_id) else None %}