VB.NET PDF: How to HTML5 PDF Viewer PDF Create PDF Export File & Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF PDF Viewer Work with Other SDKs Barcode Read Barcode Create OCR Twain
Password: Open Document
  |  
Home ›› XDoc.PDF ›› VB.NET PDF: Edit PDF Password

VB.NET PDF - Apply PDF Password with Access Permission in VB.NET


Help to Improve the Security of Your PDF Document by Setting Password in VB.NET Program




Password is a common way to be used for Document Protection. RasterEdge XDoc.PDF SDK provides some PDF security settings about password to help protect your PDF document in VB.NET project. On this page, we will illustrate how to protect PDF document via password by using simple VB.NET demo code. In general, you can do following manipulations.


Open password protected PDF


Add password to PDF


Change PDF original password


Remove password from PDF


Set PDF security level




VB.NET: Necessary DLLs for PDF Password Edit



In order to run the sample code, the following steps would be necessary.


Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XDoc.Raster.dll


  RasterEdge.XDoc.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;




VB: Use Password to Access PDF Document



This Visual Basic coding example will help you open an encrypted PDF file.




' Define input file path.
Dim intputFilePath As String = Program.RootPath + "\\" + "1.pdf"

' Input password.
Dim userPassword As String = "you"

' Open an encrypted PDF document.
Dim doc As PDFDocument = PDFDocument.Open(intputFilePath, userPassword)

' Define output file path.
Dim outputFilePath As String = Program.RootPath + "\\" + "Output.pdf"

' Remove the password.
doc.Save(outputFilePath)





VB: Add Password to Plain PDF File



Following are examples for adding password to a plain PDF file in Visual Basic programming.




' Define input and output files path.
Dim intputFilePath As String = Program.RootPath + "\\" + "1.pdf"
Dim outputFilePath As String = Program.RootPath + "\\" + "1_with_pw.pdf"

' Set passwords for user and owner.
Dim userPassword As String = "you"
Dim ownerPassword As String = "me"

' Create password setting.
Dim setting As PasswordSetting = New PasswordSetting(userPassword, ownerPassword)

' Add password to plain PDF file and output a new file.
Dim errorCode As Integer = PDFDocument.AddPassword(intputFilePath, outputFilePath, setting)
If errorCode = 0 Then
    Console.WriteLine("Success")
Else
    Console.WriteLine("Failed")
End If





' Define input file path.
Dim intputFilePath As String = Program.RootPath + "\\" + "1.pdf"

' Set passwords for user and owner.
Dim userPassword As String = "you"
Dim ownerPassword As String = "me"

' Create password setting.
Dim setting As PasswordSetting = New PasswordSetting(userPassword, ownerPassword)

' Add password to plain PDF file and overwrite the original file.
Dim errorCode As Integer = PDFDocument.AddPassword(intputFilePath, setting)
If errorCode = 0 Then
    Console.WriteLine("Success")
Else
    Console.WriteLine("Failed")
End If





VB: Add Password to PDF with Permission Settings Applied



This VB.NET example shows how to add PDF file password with access permission setting.




' Define input and output file path.
Dim inputFilePath As String = Program.RootPath + "\\" + "3.pdf"
Dim outputFilePath As String = Program.RootPath + "\\" + "3_pw_a.pdf"

' Create a password setting object with user password which is "Hello World".
Dim passwordSetting As PasswordSetting = New PasswordSetting("Hello World")

' Set encryption level to AES-128.
passwordSetting.Level = EncryptionLevel.AES_128bit

' Print is allowed.
passwordSetting.IsPrint = True

' Print with high-resolution.
passwordSetting.IsHighReso = True

' Allow to change document.
passwordSetting.IsModify = True

' Annotation is allowed.
passwordSetting.IsAnnot = True

' Allow to fill form.
passwordSetting.IsFillForm = True

' Content extraction is allowed.
passwordSetting.IsExtract = True

' Copy is allowed.
passwordSetting.IsCopy = True

' Allow to assemble document.
passwordSetting.IsAssemble = True

' Add password to PDF file.
PDFDocument.AddPassword(inputFilePath, outputFilePath, passwordSetting)





VB: Change and Update PDF Document Password



In this part, you will know how to change and update password for an encrypted PDF file in VB.NET programming.




' Define input and output file path.
Dim intputFilePath As String = Program.RootPath + "\\" + "1.pdf"
Dim outputFilePath As String = Program.RootPath + "\\" + "1_with_pw.pdf"

' Set PDF passwords.
Dim userPassword As String = "you"
Dim newUserPassword As String = "fill"
Dim newOwnerPassword As String = "watch"

' Create setting for the new password.
Dim setting As PasswordSetting = New PasswordSetting(newUserPassword, newOwnerPassword)

' Change password for an encrypted PDF file and output to a new file.
Dim errorCode As Integer = PDFDocument.ChangePassword(intputFilePath, outputFilePath, userPassword, setting)
If errorCode = 0 Then
    Console.WriteLine("Success")
Else
    Console.WriteLine("Failed")
End If





' Define input file path.
Dim intputFilePath As String = Program.RootPath + "\\" + "1.pdf"

' Set PDF passwords.
Dim userPassword As String = "you"
Dim newUserPassword As String = "fill"
Dim newOwnerPassword As String = "watch"

' Create setting for the new password.
Dim setting As PasswordSetting = New PasswordSetting(newUserPassword, newOwnerPassword)

' Change password for an encrypted PDF file.
Dim errorCode As Integer = PDFDocument.ChangePassword(intputFilePath, userPassword, setting)
If errorCode = 0 Then
    Console.WriteLine("Success")
Else
    Console.WriteLine("Failed")
End If





VB: Remove Password from PDF File



These two demos will help you to delete password for an encrypted PDF file.




' Define input file path.
Dim intputFilePath As String = Program.RootPath + "\\" + "1.pdf"

' Set user password.
Dim userPassword As String = "you"

' Define output file path.
Dim outputFilePath As String = Program.RootPath + "\\" + "Remove.pdf"

' Remove password in the input file and output to a new file.
Dim errorCode As Integer = PDFDocument.RemovePassword(intputFilePath, outputFilePath, userPassword)
If errorCode = 0 Then
    Console.WriteLine("Success")
Else
    Console.WriteLine("Failed")
End If





' Define input file path.
Dim intputFilePath As String = Program.RootPath + "\\" + "1.pdf"

' Set user password.
Dim userPassword As String = "you"

' Remove password in the file.
Dim errorCode As Integer = PDFDocument.RemovePassword(intputFilePath, userPassword)
If errorCode = 0 Then
    Console.WriteLine("Success")
Else
    Console.WriteLine("Failed")
End If