Request Password

Request Password

Forum member · Nov 16, 2017
Hello, I need to ask to the user the password to open a PDF file. The problem is that I don't know if the file needs the passowrd or not. Can you show me an example in C# of how to know if a PDF file is password-protected or not? Thanks a lot v

Re: Request Password

Support · Nov 16, 2017
Hello, There is no option available in DynamicPDF Viewer API to detect whether the PDF is password protected or not. You can load the PDF using PdfDocument class constructor by specifying empty string as password . If the PDF being loaded is password protected then the Viewer API throws InvalidPasswordException. You can catch this error and decide on further process. Below is the code sample for catching InvalidPasswordException while loading the PDF. try { PdfDocument pdf = new PdfDocument(@"Path for PDF", ""); pdfViewer1.Open(pdf); } catch (InvalidPasswordException ex) { MessageBox.Show("PDF is password protected"); } Thanks, ceTe Software Support Team.