PDF Mosaic: How to protect your PDF document with a password


Home       Features       Download       Tutorial       Version History       License       PDF Mosaic Blog       Source Code

 

This sample shows how to protect your PDF document with a password.

There are two passwords types: a “user” and an “owner” password:

  • PDFSecurity.OwnerPassword property is for an “owner” password
  • PDFSecurity.UserPassword property is for a “user” password

 

C# :

using PDFMosaic;
using System;
 
namespace SetPassword
{
  class SetPassword
  {
    static void Main()
    {
      PDFDocument document = new PDFDocument();
      document.Pages.Add(new PDFPage(PDFPaperFormat.A4));
 
      document.Security.EncryptionAlgorithm = PDFEncryptionAlgorithm.el40bitRC4;
      document.Security.UserPassword = "test";
 
      document.Save("SetPassword.pdf", true);
    }
  }
}

 

Visial Basic.NET :

Imports PDFMosaic
Imports System
 
Module SetPassword
  Sub Main()
    Dim document As New PDFDocument()
    document.Pages.Add(New PDFPage(PDFPaperFormat.A4))
 
    document.Security.EncryptionAlgorithm = PDFEncryptionAlgorithm.el40bitRC4
    document.Security.UserPassword = "test"
 
    document.Save("SetPassword.pdf", True)
  End Sub
End Module

 


Home       Features       Download       Tutorial       Version History       License       PDF Mosaic Blog       Source Code