Whenever we click on the print button or PDF in the ERPNext system, system create a record in the Access Log with details such as export_from: 'Payment Entry'
, reference_document: frm.doc.name
, file_type: 'PDF'
, and method: 'Print'
.
You can create logic to connect this and restrict the printing if needed.
I have implemented a similar feature to display “Original” on the first print and “Duplicate” on subsequent prints by using Jinja.
<div class="print-heading">
<h2>
{% if frappe.get_list("Access Log", filters={
"reference_document": doc.name,
"file_type": "PDF",
"method": "Print"
})|length > 1
%}
<div>Duplicate</div>
{% else %}
<div>Original</div>
{% endif %}
<small class="sub-heading">{{ doc.name }}</small>
</h2>
</div>