How do I set permissions and security on a PDF document?

Q: I need instructions or a code snippet to set security on a PDF
document that does not allow a user to alter or copy any content of
the document. The user is allowed to print only. I could not find a
clear example for how to do this.
----
A:

Standard PDF security handler supports two passwords:
   master/owner/permission password, and user/open password.

You can set these passwords using ChangeMasterPassword() and
ChangeUserPassword() in SecurityHandler.

For example:

// Assuming C#
// Apply a new security handler with given security settings.
// In order to open saved PDF you will need a user password 'test'.
SecurityHandler new_handler = new StdSecurityHandler(); // or
SecurityHandler

// Set a new password required to open a document string user_pass =
"pass1"; string new_handler.ChangeUserPassword("mypass1");
new_handler.ChangeMasterPassword ("mypass2");

// Set Permissions
new_handler.SetPermission (SecurityHandler.Permission.e_print, true);
new_handler.SetPermission
(SecurityHandler.Permission.e_extract_content, false);
...
doc.SetSecurityHandler(new_handler);