Dymanic password protected PDF email attachments

Hello!

We want to send pdf documents as attachments via email, and we would like to secure them with a dynamic/custom password: i.e. last 5 digits of personal identification number or last 5 digits of company registration number
Can someone advise how to achieve this?

thank you!

The following Control script snippet allows you to dynamically set the password for PDF attachments created based on the Print context.

merge.template.contexts.PRINT.sections['Section 1'].password = record.fields.someField;