private PDFFile BrowsePDFDocument(bool pdfOnly, out bool isPostscript) { isPostscript = false; string fileName = RunPDFOpenFileDialog(pdfOnly); if (fileName == null) { return(null); } try { PDFFileType fileType = PDFFile.GetPDFFileType(fileName, pdfOnly); if (fileType == PDFFileType.Unknown) { if (pdfOnly) { Messager.ShowError(this, string.Format("Not a valid PDF file.\n\n{0}", fileName)); } else { Messager.ShowError(this, string.Format("Not a valid PDF or Postscript file.\n\n{0}", fileName)); } return(null); } if (fileType == PDFFileType.Postscript || fileType == PDFFileType.EncapsulatedPostscript) { isPostscript = true; } if (!isPostscript) { string password = null; // Check if it is encrypted if (PDFFile.IsEncrypted(fileName)) { using (GetPasswordDialog dlg = new GetPasswordDialog()) { if (dlg.ShowDialog(this) == DialogResult.OK) { password = dlg.Password; } else { return(null); } } } using (WaitCursor wait = new WaitCursor()) { PDFFile document = new PDFFile(fileName, password); document.Load(); return(document); } } else { PDFFile document = new PDFFile(fileName); return(document); } } catch (Exception ex) { Messager.ShowError(this, ex.Message); } return(null); }