Crash when opening PDF file with password

8 Replies 1 reply marked as answer

VD Vikram Devaraj Syncfusion Team December 18, 2023 11:44 AM UTC

Hi Shompinice,

We could see in your provided sample that you didn't handle loading the password protected documents. If you are trying to load the encrypted document without a password, it will throw a PDFException. To load the encrypted document, please follow the below steps:

To find the encrypted document, you need to use a try-catch block while loading.

Way -1

try

{

ldoc = new PdfLoadedDocument(stream);

pdfViewer.LoadDocument(fileStream);

}

catch (PdfException pdfException)

{

if (pdfException.Message == "Can't open an encrypted document. The password is invalid.")

 {

  var password = "XYZ";

  pdfViewer.LoadDocument(fileStream, password);

 }

}


Way -2

try

{

ldoc = new PdfLoadedDocument(stream);

pdfViewer.LoadDocument(fileStream);

}

catch (PdfException pdfException)

{

if (pdfException.Message == "Can't open an encrypted document. The password is invalid.")

 {

  ldoc = new PdfLoadedDocument(stream, password);

  pdfViewer.LoadDocument(ldoc);

 }

}

Note: Currently, we don’t have support to show the default password popup in our control. You can create your own password popup if needed and using that entered password text, you can load the encrypted document with the above suggestion.


Marked as answer

SH Shompinice December 26, 2023 09:31 AM UTC

After a week of hard work... I tried to create a password input box myself but failed, could you guys provide a copy of a modified solution as you demonstrated?


In theory it should also contain a detection that should not pop up a dialog box when the DPF file is not encrypted



password is:

ymky-edu.taobao.com

fjnu611805-【2】真题及参考答案.pdf



SH Shompinice replied to Vikram Devaraj December 27, 2023 04:10 AM UTC

After a week of hard work... I tried to create a password input box myself but failed, could you guys provide a copy of a modified solution as you demonstrated?


In theory it should also contain a detection that should not pop up a dialog box when the DPF file is not encrypted



password is:

ymky-edu.taobao.com

fjnu611805-【2】真题及参考答案.pdf



VD Vikram Devaraj Syncfusion Team December 27, 2023 06:39 PM UTC

Hi Shompinice,

We have created a sample based on your requirement to load the encrypted document using a password entry popup and attached the sample for the same below. We have simply created a password entry popup to demonstrate your requirements. However, with the same provided logic, you can customize your own password entry popup. 


Attachment: PDFViewer_48659a4.zip


SH Shompinice replied to Vikram Devaraj December 28, 2023 01:51 AM UTC

Is it possible to create the password dialog using XAML in the example instead of using C#? I'm not very familiar with customizing styles in C#, and using XAML I would be able to modify it to conform to Windows design guidelines.


Original project without password dialog

https://www.syncfusion.com/downloads/support/forum/185591/ze/PDFViewer_a218362e

The project you modified in your previous reply

https://www.syncfusion.com/downloads/support/forum/185885/ze/PDFViewer_48659a4



MA ManojKumar Arumugasamy Syncfusion Team December 28, 2023 05:36 PM UTC

Hi Shompinice,

We have modified the sample to create a password dialog using XAML. Kindly find the sample in the following link, https://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfViewer_1126160908




SH Shompinice replied to ManojKumar Arumugasamy December 29, 2023 05:27 AM UTC

图片_3658_17038275576​​17

With your help, I modified the look based on yours so that it looks like it gets a consistent look with Windows 11. this looks awesome



MA ManojKumar Arumugasamy Syncfusion Team January 2, 2024 04:25 AM UTC

Thank you for your reply. I'm glad to hear that the issue you were experiencing has been resolved. We're marking this ticket as closed.

If you have any other questions or concerns, please don't hesitate to contact us.


Loader.
Up arrow icon