Encrypting PDF documents in memory and on the fly.

Q:

I have a need to take pdf documents I have created in another process,
which are contained in a memory stream object, and are not on disk,
and simply encrypt them with a password. I would be doing this on a
single server, from a service I wrote, and doing it to dozens if not
hundreds of pdf documents each day.
----

A:

You can use PDFNet SDK (www.pdftron.com/net) to secure/encrypt PDF
documents on the fly.

For an example of how to open & save PDF documents from memory buffer
please take a look at PDFDocMemory sample project (http://
www.pdftron.com/net/samplecode.html#PDFDocMemory).

For an example of how to encrypt existing PDF documents please take a
look at EncTest sample project (http://www.pdftron.com/net/
samplecode.html#EncTest):

StdSecurityHandler new_handler = new StdSecurityHandler();

// Set a new password required to open a document
string my_password = "test";
new_handler.ChangeUserPassword(new
System.Text.UTF8Encoding().GetBytes(my_password));

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

pdfdoc.SetSecurityHandler(new_handler);