How can I make a PDF non-printable programmatically using .net?
Short answer. You can't. You can try to set a DRM parameter to prevent printing, but that all depends on the client's software for rendering the PDF and if it respects DRM or no.
Also, assuming you are able to view a PDF there is nothing preventing the user from taking screen captures of the contents presented in the PDF.
Sure you can prevent printing! Of course you cannot prevent a screen capture, but you can definitely prevent a casual user from printing a PDF in the Adobe Reader. I know in our ActiveReports product when we export PDF you can specify various security options that determine whether the user viewing the PDF can print or not. The developer can specify an admin password that can be used to enable only some users to print, while preventing those without the password from printing.
You can read more about this in the PdfSecurity enumeration documentation of ActiveReports. A code sample is in the documentation here. Follow some links on that page to see more information.
If you want to load an existing PDF and modify usually people suggest iTextSharp. Although I have not used it, other people recommend it highly and I think it will work for this read+modify scenario. I managed to find an example of how you can use iTextSharp to enable/disable the "AllowPrint" and other permissions here.
Sounds like you're really looking for a group policy object in Active Directory that prevents users from printing, perhaps?
update
What prevents said users from emailing the PDF to themselves and printing at home, other than another GPO that prevents attachments with given extensions or over certain sizes?
The PDF spec allows for the setting of an owner and a user password. If the owner password is set, you've got a number of other options that can also be set, such as disallowing printing, disallowing high quality printing, disallowing copy/paste, etc.
I think there are a number of PDF creation libraries that might allow the setting of these parameters ( do a search here for a list ).
We built our own product in order to try to simplify the problem - you just pass us the URL of the content you want as a PDF and it returns the PDF. You can specify a number of switches on the URL, one of which is to disable the printing. Don't know if it helps in your scenario, but the solution is here http://fourpdf.com/
Regards, Jake.
Hi Ryan,
You've got a number of options depending on the full requirement details but the easiest would indeed be to set password encryption on the document. As some of the folks above mentioned, you can set an owner password and user password to encrypt the document. The owner password basically allows admin level access and fully opens up the document to all operations. The user password opens up the document but access is limited to what you specified at the time of encryption, e.g., if you turn turn off printing rights, then someone who supplies the user password won't be able to print the PDF.
We offer a solution that supports .NET and can easily encrypt and also decrypt PDFs. Here's a link to the API docs if you're interested in giving it a look:
http://www.pdfonline.com/easypdf/epsdk_manual/index.htm?page=reference%2Fpdfprocessorsdk%2Fpdfprocessor%2Fm_encrypt.htm
The idea would be to call the Encrypt() function above and pass a PrintingPerm argument of PRC_SEC_PRINT_PERM_NONE. You can also set other access permissions like modification, copy/paste, etc., if you like.
Hope this helps.