This sample shows how to protect your PDF document with a password.
There are two passwords types: a "user" and an "owner" password. PdfDocument.OwnerPassword property is for an "owner" password and PdfDocument.UserPassword property is for a "user" password.
Opening a PDF document with an "owner" password allows a reader of your document to do everything with opened document. Opening a PDF document with a "user" password allows a reader of your document to only perform operation allowed by user access permissions.
using System.Diagnostics; namespace BitMiracle.Docotic.Pdf.Samples { public static class SetPassword { public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. PdfDocument pdf = new PdfDocument(); pdf.UserPassword = "test"; string pathToFile = "SetPassword.pdf"; pdf.Save(pathToFile); pdf.Dispose(); Process.Start(pathToFile); } } }
Imports System.Diagnostics Imports BitMiracle.Docotic.Pdf Namespace BitMiracle.Docotic.Pdf.Samples Public NotInheritable Class SetPassword Public Shared Sub Main() ' NOTE: ' When used in trial mode, the library imposes some restrictions. ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx ' for more information. Dim pdf As New PdfDocument() pdf.UserPassword = "test" Dim pathToFile As String = "SetPassword.pdf" pdf.Save(pathToFile) pdf.Dispose() Process.Start(pathToFile) End Sub End Class End Namespace
