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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

116957 Jul 9,2014 12:32 PM Jul 24,2014 12:15 AM WinRT 6
loading
Tags: SfPdfViewer
Kurt Farrar (CW)
Asked On July 9, 2014 12:32 PM

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

Kurt Farrar (CW)
Replied On July 10, 2014 06:44 AM

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?

Suresh M [Syncfusion]
Replied On July 11, 2014 08:22 AM

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


Denis Briel
Replied On July 22, 2014 01:44 AM

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

Kurt Farrar (CW)
Replied On July 22, 2014 01:51 AM

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

Denis Briel
Replied On July 22, 2014 02:01 AM

Hi,

no problem. :)

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

Reagrds
Denis

Suresh M [Syncfusion]
Replied On July 24, 2014 12:15 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;