Add Password Protection To Word Or PDF Files In C#

Everything is going digital. There are outstanding products/tools to pull you into the paperless era. We share information across companies or anywhere in the form of different file formats. It could be a Spreadsheet, PDF, or any of the MS Office formats. But the biggest threat is security. Let’s understand this with a use-case.  

You want to secure a Spreadsheet, Presentation, Word or a PDF file on a machine where MS Office or Adobe PDF is not installed, in that case, you need a tool or API that can secure such documents programmatically without any dependency.
Have a look at the GroupDocs.Merger for .NET code below.


One interesting thing about this API is that it gives you two options,

  • Pass a source file and specify its extension as well and save output/protected file with the same extension (source: “test.pdf”, output: “test.pdf”)
  • Secondly, you can pass the source file and for the output you just have to specify the file name and the API will detect file extension on its own based on the source file (source: “test.pdf”, output: “test.”+result.FileFormat)

Below is the output of a password protected PDF file.

If you face any issue regarding API integration or operations, please post on forum.

Share on FacebookTweet about this on TwitterShare on LinkedIn