private void Open_Click(object sender, EventArgs e) { if (ofdOpen.ShowDialog(this) != DialogResult.OK) { return; } while (true) { try { c1PdfDocumentSource1.LoadFromFile(ofdOpen.FileName); return; } catch (PdfPasswordException) { string password = PasswordForm.DoEnterPassword(ofdOpen.FileName); if (password == null) { return; } c1PdfDocumentSource1.Credential.Password = password; } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } }
private void btnExecute_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbFile.Text)) { MessageBox.Show(this, "Please select a PDF file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!File.Exists(tbFile.Text)) { MessageBox.Show(this, string.Format("File \"{0}\" does not exist.", tbFile.Text), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // load document while (true) { try { c1PdfDocumentSource1.LoadFromFile(tbFile.Text); break; } catch (PdfPasswordException) { string password = PasswordForm.DoEnterPassword(tbFile.Text); if (password == null) { return; } c1PdfDocumentSource1.Credential.Password = password; } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } // execute action if (cbAction.SelectedIndex == 0) { DoPrint(c1PdfDocumentSource1); } else { DoExport(c1PdfDocumentSource1, ((FileAction)cbAction.SelectedItem).ExportProvider); } }