private void btnEncrypte_Click(object sender, RoutedEventArgs e)
        {
            //open a pdf document
            OpenFileDialog dialog = new OpenFileDialog()
            {
                Filter           = "Pdf document(*.Pdf)|*.pdf",
                Title            = "Open Pdf Document",
                Multiselect      = false,
                InitialDirectory = System.IO.Path.GetFullPath(@"..\..\..\..\..\..\Data")
            };
            bool?  result  = dialog.ShowDialog();
            string pdfFile = dialog.FileName;

            if (result.Value)
            {
                try
                {
                    //Load pdf document from file.
                    this.pdfDocumentViewer1.LoadFromFile(pdfFile);
                }
                catch (Exception ex)
                {
                    while (true)
                    {
                        string passError = " password is invalid";
                        string message   = ex.Message;
                        if (message.IndexOf(passError) > -1)
                        {
                            string info = pdfFile + " has password! \n\r You need input it's password!";

                            PasswordDlg passwordDialog = new PasswordDlg();

                            bool?dlgResult = passwordDialog.ShowDialog();
                            if (!dlgResult.Value)
                            {
                                break;
                            }
                            string password = passwordDialog.getPass();
                            if (!String.IsNullOrEmpty(password))
                            {
                                passwordDialog.Close();
                                try
                                {
                                    //Open encryption pdf document from file.
                                    this.pdfDocumentViewer1.LoadFromFile(pdfFile, password);
                                    break;
                                }
                                catch (Exception ex1)
                                {
                                    MessageBox.Show(ex1.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void BtnOpenPass_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "PDF document (*.pdf)|*.pdf";

            DialogResult result  = dialog.ShowDialog();
            string       pdfFile = dialog.FileName;

            if (result == DialogResult.OK)
            {
                try
                {
                    this.pdfDocumentViewer1.LoadFromFile(pdfFile);
                }
                catch (Exception exe)
                {
                    while (true)
                    {
                        string passError = " password is invalid";
                        string message   = exe.Message;
                        if (message.IndexOf(passError) > -1)
                        {
                            string      info = pdfFile + " has password !\n You  need input its password!";
                            PasswordDlg dlg  = new PasswordDlg();

                            DialogResult dlgResult = dlg.ShowDialog();
                            if (dlgResult == DialogResult.Cancel)
                            {
                                break;
                            }
                            string pass = dlg.getPass();
                            if (!String.IsNullOrEmpty(pass))
                            {
                                try
                                {
                                    this.pdfDocumentViewer1.LoadFromFile(pdfFile, pass);
                                    dlg.Dispose();
                                    break;
                                }
                                catch (Exception exc)
                                {
                                    dlg.Dispose();
                                }
                            }
                        }
                    }
                }
            }
        }
        private void btnEncrypte_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog()
            {
                Filter = "Pdf document(*.Pdf)|*.pdf",
                Title = "Open Pdf Document",
                Multiselect = false,
                InitialDirectory =System.IO.Path.GetFullPath(@"..\..\..\..\..\..\Data")
            };
            bool? result = dialog.ShowDialog();
            string pdfFile = dialog.FileName;
            if (result.Value)
            {
                try
                {
                    //Load pdf document from file.
                    this.pdfViewer1.LoadFromFile(pdfFile);
                }
                catch (Exception ex)
                {
                    while (true)
                    {
                        string passError = " password is invalid";
                        string message = ex.Message;
                        if (message.IndexOf(passError) > -1)
                        {
                            string info = pdfFile + " has password! \n\r You need input it's password!";
                            PasswordDlg passwordDialog = new PasswordDlg();

                            bool? dlgResult = passwordDialog.ShowDialog();
                            if (!dlgResult.Value)
                            {
                                break;
                            }
                            string password = passwordDialog.getPass();
                            if (!String.IsNullOrEmpty(password))
                            {
                                passwordDialog.Close();
                                try
                                {
                                    //Open encryption pdf document from file.
                                    this.pdfViewer1.LoadFromFile(pdfFile, password);
                                    break;
                                }
                                catch (Exception ex1)
                                {

                                }
                            }
                        }
                    }
                }

            }
        }
Пример #4
0
        private void BtnOpenPass_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "PDF document (*.pdf)|*.pdf";
          
            DialogResult result = dialog.ShowDialog();
             string pdfFile = dialog.FileName;
            if (result == DialogResult.OK)
            {
               
                try
                {
                   
                    this.pdfDocumentViewer1.LoadFromFile(pdfFile);
                }
                catch (Exception exe)
                {
                    while (true)
                    {
                        string passError = " password is invalid";
                        string message = exe.Message;
                        if (message.IndexOf(passError) > -1)
                        {
                            string info = pdfFile + " has password !\n You  need input its password!";
                            PasswordDlg dlg = new PasswordDlg();

                           DialogResult dlgResult= dlg.ShowDialog();
                           if (dlgResult == DialogResult.Cancel)
                               break;                        
                            string pass = dlg.getPass();
                            if (!String.IsNullOrEmpty(pass))
                            {
                                try
                                {
                                    this.pdfDocumentViewer1.LoadFromFile(pdfFile, pass);
                                    dlg.Dispose();
                                    break;
                                }
                                catch (Exception exc)
                                {
                                    dlg.Dispose();
                                }
                            }
                        }
                    }
                }


            }

        }