Viscomsoft .NET PDF Viewer SDK

PDFDocument.applyPassword Method

 

Appy the password when open password protected PDF file.

 Visual Basic

Public Sub applyPassword(ByVal password As String) as Bool

 
 C#

public bool applyPassword(string password)

 


Parameter
password - the path of password.

Namespace: Viscomsoft.PDFViewer

Return Value
True - Open successful
False - Open failed.

Example

   

[C# Syntax] 
using Viscomsoft.PDFViewer;

public partial class Form1 : Form
{

  public PDFView _pdfViewer;
  _pdfViewer = new PDFView();
  _pdfViewer.Canvas.Parent = this;
  _pdfViewer.Canvas.Location = new Point(0, 24);

  private void Form1_Load(object sender, EventArgs e)
  {
    resizeCanvas();

    PDFDocument doc = new PDFDocument();
    if (doc.open("c:\\yourfile.pdf"))
    {
        if (doc.RequiresPassword)
         {
               bool Isopen = doc.applyPassword("yourpassword");
                    if (!Isopen)
                    MessageBox.Show("Invalid password", "Document is have user password");

        }
      _pdfViewer.Document = doc;
      _pdfViewer.gotoPage(1);
    
    }
  }
 

  private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  {

    if (_pdf.Document != null)
    _pdfViewer.Document.close();
   }


 

  private void resizeCanvas()
  {
  _pdfViewer.Canvas.Size = new Size(this.ClientSize.Width, this.ClientSize.Height - 24);
  }
}

 

 


 

   

[Visual Basic Syntax] 
Imports Viscomsoft.PDFViewer

Public Class Form1
 

Private Sub resizeCanvas()

  _pdfviewer.Canvas.Size = New Size(Me.ClientSize.Width, Me.ClientSize.Height - 24)

End Sub

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

  _pdfviewer.Canvas.Parent = Me

  _pdfviewer.Canvas.Location = New Point(0, 24)

  resizeCanvas()

  Dim doc As New PDFDocument

  If doc.open("c:\temp\yourfile.pdf") Then

    If doc.RequiresPassword then
                   Dim Isopen as Bool
                      Isopen = doc.applyPassword("yourpassword")
                    if Isopen <> true Then
                    MessageBox.Show("Invalid password", "Document is have user password")
    End If

  _pdfviewer.Document = doc

  _pdfviewer.gotoPage(1)
  _pdfViewer.saveText("c:\temp\mytext.txt")
  End If

End Sub

Private Sub Form1_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed

  If Not IsNothing(_pdfviewer.Document) Then

  _pdfviewer.Document.close()

   End If

End Sub


End Class