We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Unable to open any PDF following the samples (Windows 8.0)

Hi, 

I've followed the examples, and tried with 2 different PDF files (attached).

I've used the following code:

StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(filename);


            var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

            Stream fileStream = stream.AsStreamForRead();


            pdfViewer.LoadDocument(fileStream);


Based on the following code:

var picker = new FileOpenPicker();

picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;

picker.ViewMode = PickerViewMode.List;

picker.FileTypeFilter.Add(".pdf");

var file = await picker.PickSingleFileAsync();

if (file == nullreturn;

var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

Stream fileStream = stream.AsStreamForRead();

pdfViewer.LoadDocument(fileStream);

Taken from: 

http://help.syncfusion.com/UG/winrt/default.htm#!Documents/viewingpdf.htm 

And get the following exception:

System.ArgumentNullException
   at Syncfusion.Pdf.Parsing.PdfLoadedPageCollection..ctor(PdfDocumentBase document, PdfCrossTable crossTable)
   at Syncfusion.Pdf.Parsing.PdfLoadedDocument.get_Pages()
   at Syncfusion.Pdf.Parsing.PdfLoadedDocument.get_PageCount()
   at Syncfusion.Windows.PdfViewer.PdfDocumentView.set_LoadedDocument(PdfLoadedDocument value)
   at Syncfusion.Windows.PdfViewer.SfPdfViewerControl.LoadDocument(PdfLoadedDocument loadedDocument)
   at Syncfusion.Windows.PdfViewer.SfPdfViewerControl.SfPdfViewerControl_SizeChanged(Object sender, SizeChangedEventArgs e)

The file object references the correct file, and the fileStream has a valid length. I'm using the same code to load and manipulate files from local storage elsewhere within my application so I can't see that being the problem. Are there some default values that I need to set on the pdfViewer control?



Attachment: Sample_PDFs_e460c498.zip

6 Replies

KF Kurt Farrar (CW) July 10, 2014 10:44 AM UTC

Interestingly I deploy the same code to a Windows 8.1 device (via remote debugging) and the code runs without error. 

This appears to be specific to Windows 8.0 (which unfortunately is our target environment) - any ideas?


SM Suresh M Syncfusion Team July 11, 2014 12:22 PM UTC

Hi Kurt,

 

Thank you for using Syncfusion products.

 

We are not able to reproduce the issue mentioned. We maintain separate implementation of PDF Viewer for .Net framework 4.5 (Windows 8) and for .Net framework 4.5.1 (Windows 8.1). The PDF viewer for Windows 8.1 cannot be deployed to a machine with Windows 8, since it does not support .Net framework 4.5.1. Kindly find the below sample for deploying the PDF Viewer in different operating systems.

 

Sample for Windows 8: http://www.syncfusion.com/downloads/support/directtrac/general/PDFViewerWintRT_2012672990118.zip

 

Sample for Windows 8.1: http://www.syncfusion.com/downloads/support/directtrac/general/PDFViewerWintRT_201363968850.zip

 

Assemblies to run the sample for Windows 8 will be available in the location

$SystemDrive:\Users\$UserName$\AppData\Local\Syncfusion\EssentialStudio\12.1.0.43\WinRT\SampleBrowser\Common\Common\DirectXAssembly\8.0

 

Assemblies to run the sample for Windows 8 will be available in the location

$SystemDrive:\Program Files (x86)\Syncfusion\Essential Studio\ 12.1.0.43\Assemblies for WinRT\8.1

 

Note: In above location for finding the assemblies version is Essential studio is assumed to be 12.1.0.43.

 

Please let us know if you need any further assistance.

 

Thanks,

Suresh



DB Denis Briel replied to Kurt Farrar July 22, 2014 05:44 AM UTC

Hi, 

I've followed the examples, and tried with 2 different PDF files (attached).

I've used the following code:

StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(filename);


            var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

            Stream fileStream = stream.AsStreamForRead();


            pdfViewer.LoadDocument(fileStream);


Based on the following code:

var picker = new FileOpenPicker();

picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;

picker.ViewMode = PickerViewMode.List;

picker.FileTypeFilter.Add(".pdf");

var file = await picker.PickSingleFileAsync();

if (file == nullreturn;

var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

Stream fileStream = stream.AsStreamForRead();

pdfViewer.LoadDocument(fileStream);

Taken from: 

http://help.syncfusion.com/UG/winrt/default.htm#!Documents/viewingpdf.htm 

And get the following exception:

System.ArgumentNullException
   at Syncfusion.Pdf.Parsing.PdfLoadedPageCollection..ctor(PdfDocumentBase document, PdfCrossTable crossTable)
   at Syncfusion.Pdf.Parsing.PdfLoadedDocument.get_Pages()
   at Syncfusion.Pdf.Parsing.PdfLoadedDocument.get_PageCount()
   at Syncfusion.Windows.PdfViewer.PdfDocumentView.set_LoadedDocument(PdfLoadedDocument value)
   at Syncfusion.Windows.PdfViewer.SfPdfViewerControl.LoadDocument(PdfLoadedDocument loadedDocument)
   at Syncfusion.Windows.PdfViewer.SfPdfViewerControl.SfPdfViewerControl_SizeChanged(Object sender, SizeChangedEventArgs e)

The file object references the correct file, and the fileStream has a valid length. I'm using the same code to load and manipulate files from local storage elsewhere within my application so I can't see that being the problem. Are there some default values that I need to set on the pdfViewer control?



Attachment: Sample_PDFs_e460c498.zip

Hi Kurt,

in which method are you trying to open the file?

After a lot of trial and error I have figured out, that when loading the document in the  "OnNavigatedTo" method, the error you describe occurs.

My solution was to start a timer in the OnNavigatedTo method, which delays the loading:

  
StorageFile file;
DispatcherTimer t;
protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            file = (StorageFile)e.Parameter;
            if (file != null)
            {
                t = new DispatcherTimer();
                t.Tick += t_Tick;
                t.Interval = new TimeSpan(0, 0, 1);
                t.Start();
            }
        }


 void t_Tick(object sender, object e)
        {
            Load();
            t.Stop();
        }

        async private void Load()
        {
            var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
            Stream fileStream = stream.AsStreamForRead();
            byte[] buffer = new byte[fileStream.Length];
            fileStream.Read(buffer, 0, buffer.Length);
            PdfLoadedDocument ldoc = new PdfLoadedDocument(buffer);
            pdfViewer.LoadDocument(ldoc);
         }

Although it's a workaround,this works for me.

Regards
Denis


KF Kurt Farrar (CW) July 22, 2014 05:51 AM UTC

Hi,

Apologies for not coming back to you, I was running the code in the OnNavigatedTo method. 

I'd actually managed to get around it without realising. I must have moved the code which go past the problem as you'd experienced.

Thanks however for your help, it certainly will stop me (and others) bashing my head against a brick wall next time. 

Kurt


DB Denis Briel July 22, 2014 06:01 AM UTC

Hi,

no problem. :)

I just saw your post and thought i should share my solution.

Reagrds
Denis


SM Suresh M Syncfusion Team July 24, 2014 04:15 AM UTC

Hi Kurt,

Thank you for your response.

We are glad to hear that your issue is resolved. 

Please let us know if you need any further assistance.

Thanks,
Suresh

Loader.
Live Chat Icon For mobile
Up arrow icon