예제 #1
0
        private void btnExecute_Click(object sender, RoutedEventArgs e)
        {
            if (fpFile.SelectedFile == null)
            {
                MessageBox.Show(this, "Please select a PDF file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // load document
            while (true)
            {
                try
                {
                    pdfDocumentSource.LoadFromFile(fpFile.SelectedFile.FullName);
                    break;
                }
                catch (PdfPasswordException)
                {
                    var password = PasswordWindow.DoEnterPassword(fpFile.SelectedFile.FullName);
                    if (password == null)
                    {
                        return;
                    }
                    pdfDocumentSource.Credential.Password = password;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            // execute action
            if (cbAction.SelectedIndex == 0)
            {
                DoPrint(pdfDocumentSource);
            }
            else
            {
                DoExport(pdfDocumentSource, (ExportProvider)((C1ComboBoxItem)cbAction.SelectedItem).Tag);
            }
        }
        public static string DoEnterPassword(string fileName)
        {
            PasswordWindow f = new PasswordWindow();

            return(f.EnterPassword(fileName));
        }