private void button_Click(object sender, RoutedEventArgs e) { var openFileDialog = new OpenFileDialog() { Filter = "PDF files (*.pdf)|*.pdf" }; if (openFileDialog.ShowDialog() != true) { return; } try { textBox.Text = PdfUtils.Pdf2Text(openFileDialog.FileName); if (string.IsNullOrWhiteSpace(textBox.Text)) { MessageBox.Show("The selected pdf file does not contain any text", "Info"); } } catch (Exception ex) { textBox.Text = string.Empty; MessageBox.Show(ex.Message, "Error"); } }