Code Samples - Document Converter Pro

Example 12: Encrypt an existing PDF file (AES 128 bits) - ASP.NET

Copy the Document Converter Pro .NET assembly from the c:\program files (x86)\neevia.com\docConverterPro\.Net\ folder into your web site bin folder;
Scroll down for the C# samples

Visual Basic Copy 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
   <SCRIPT runat="server" language="VB">

     Sub Page_Load(Source As Object, e As EventArgs)

       Dim DC As New Neevia.docConverter

       DC.setParameter( "PDFEncryption", "true" )
       DC.setParameter( "PDFEncryptionType", "aes" )

       DC.setParameter( "PDFOwnerPassword", "owner" )
       DC.setParameter( "PDFUserPassword", "open" )

       ' p - disable document printing
       ' e - disable extraction of text and graphics
       DC.setParameter( "Permissions", "pe" )

       Dim RVal As Integer = DC.encryptPDF("c:\users\public\in.pdf", "c:\users\public\out.pdf")
       DC = Nothing

       If (RVal<>0) Then
         Response.Write("There was an error encrypting the document!!!")
       Else
         Response.Write("Done encrypting !!!")
       End If

     End Sub

   </SCRIPT>

VC# Copy 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
   <%@ Page Language="C#" %>
   <%@ Assembly Name = "docConverter" %>
   <%@ Import Namespace = "Neevia" %>
   <SCRIPT runat="server">

     void Page_Load(object Source, EventArgs e)
     {

       Neevia.docConverter DC = new Neevia.docConverter();

       DC.setParameter( "PDFEncryption", "true" );
       DC.setParameter( "PDFEncryptionType", "aes" );

       DC.setParameter( "PDFOwnerPassword", "owner" );
       DC.setParameter( "PDFUserPassword", "open" );

       // p - disable document printing
       // e - disable extraction of text and graphics
       DC.setParameter( "Permissions", "pe" );

       int RVal = DC.encryptPDF(@"c:\users\public\in.pdf", @"c:\users\public\out.pdf");

       DC = null;

       if (RVal != 0) { 
         Response.Write("There was an error encrypting the PDF!!!");
       }else{
         Response.Write("Done !!!");
       }    

     }

   </SCRIPT>