SfPdfViewer crash with password protected PDF

Hi,

Can SfPdfViewer open password protected PDF?
It's crashed at load method:

var stream = new FileStream(file.AbsolutePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
sfPdfViewer.LoadDocument(stream);

Thanks

3 Replies

NK Navaneetha Kannan Sudalai Muthu Syncfusion Team March 6, 2018 02:36 PM UTC

Hi Dung,  
 
You have mentioned the crash in Xamarin Forms platform. We were not able to reproduce the crash in Xamarin Forms platform. In Xamarin Forms platform there is no support for password protected PDF documents. When such PDF is loaded the UnhandledConditionOccurred event will be raised.  
 
By the code snippet you have provided we guessed that you are using UWP platform. This is not a defect of PdfViewer. Password protected PDFs can be loaded using the overload method LoadDocument(Stream stream, string password) in which the password of the PDF should be provided as the second argument.  
 
Please find the code snippet below.  
 
var stream = new FileStream(file.AbsolutePath, System.IO.FileMode.Open, System.IO.FileAccess.Read); 
sfPdfViewer.LoadDocument(stream, "password"); 
 
where the string “password” must be the corresponding password of the PDF document. 
 
We have attached a simple sample in the following link for your reference.  
 
 
Kindly place the PDF in the attachment in the local folder of the application before running the sample. The password of the PDF is “syncfusion". 
 
Kindly confirm whether the platform is UWP or Xamarin Forms. If it is Xamarin Forms, please provide us with the PDF document and a simple sample with which the issue could be reproduced. That way we will be able to understand the issue and provide a proper solution.  

Best, 
Navaneetha Kannan  



DN Dung Nguyen March 11, 2018 11:54 AM UTC

Hi Navaneetha,

Sorry for the confusion caused,
I use SfPdfViewer for Xamarin.Forms, the file stream is get from Android platform using DependencyService. The code is:

Forms:
     var stream = DependencyService.Get<IFileService>().GetFileStream(pdfFilePath);
     sfPdfViewer.LoadDocument(stream);

Android:
      public Stream GetFileStream(string filePath)
     {
            var file = new File(filePath);
            if (file.Exists())
                return new FileStream(file.AbsolutePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            return null;
     }

Can it works by that way? The attachment is the sample file, the password is "abc".

Thanks,
Dung Nguyen

Attachment: Document_Mar11_553ec680.zip


NK Navaneetha Kannan Sudalai Muthu Syncfusion Team March 12, 2018 11:39 AM UTC

Hi Dung,  
 
We are not able to reproduce the issue “Application crashes when loading password protected PDFs in PdfViewer”. We have attached a simple sample with the same code you have provided in the link below for your reference.   
 
 
 
Please place the PDF (Document Mar-11.pdf) in the local storage of the android device before running the sample or change the path in the sample as per your convenience.  
 
As we mentioned earlier, there is no support for loading password protected PDFs in Xamarin Forms platform. If a password protected PDF is loaded UnhandledConditionOccurred event will be raised which can be handled at the sample level. The same has been illustrated in the attached sample.  
 
Kindly provide us with the following details.                            
 
  1. Essential Studio version
  2. Exception details including StackTrace
 
These details will help us understand the issue better and provide you an appropriate solution.  

Best, 
Navaneetha Kannan  


Loader.
Up arrow icon