Xamarin Forms Android issues with PDF viewer

Hi,

I have been encountering the following:


(1) Android apps failed to display PDF, by default, to fit page or device's width (e.g., when rotated to landscape) even with explicit request using PdfViewer.ViewMode = ViewMode.FitWidth

However, iOS was OK.


(2) Intermittent crashes in Android when fast repeatedly, with a number of times, loading or unloading a large PDF file of a few megabytes


Code-behind of a PDF XAML page [await Navigation.PushAsync(new PdfPage());]==>

        protected override void OnAppearing()
        {
            base.OnAppearing();
            var stream  = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("MyNamespace.Assets." + App.pdfName);
            stream.Position = 0;
            pdfViewerControl.LoadDocument(stream);
        }

Thanks in advance.

Francis

P.S. By the way, is it possible to disable the PDF default busy indicator when loading a large PDF file? Thanks.



23 Replies

FT Francis Tang March 13, 2020 02:49 AM UTC

Sorry forgot mentioning. I didn't actually unload the PDF. Instead, I just left by going back to a previous page (via a back navigation arrow button).

Adding an Unload in OnDisappearing (perhaps stupid) seemed not helping (on the other hand, iPhone even crashed earlier. ) ==>

        protected override void OnDisappearing()
        {
            base.OnDisappearing();
            pdfViewerControl.Unload();
        }

Francis


JP Jhansi Priya Ramesh Syncfusion Team March 13, 2020 10:28 AM UTC

Hi Francis, 
 
Greetings from Syncfusion support. Please find the details for your queries form below, 
   
S.No   
Query   
Details   
1   
 Android apps failed to display PDF, by default, to fit page or device's width (e.g., when rotated to landscape) even with an explicit request using PdfViewer.ViewMode = ViewMode.FitWidth   
The “ViewMode” API is specific to the UWP platform and applicable for desktop applications.   
   
It is the default behavior of PdfViewer that it will not fit a device in landscape mode.    
2   
Intermittent crashes in Android when fast repeatedly, with a number of times, loading or unloading a large PDF file of a few megabytes   
We tried reproducing the issue “Application crashes while loading/unloading PDF document multiple times” in our side but it is working fine as expected. Please find the sample with which we tried to replicate the issue.   
   
   
Kindly share the following details to analyze more on this issue and assist with a better solution.   
1.       Simple sample or modify the above sample.   
2.       Sample PDF document with which we could reproduce the issue.   
3.       Exception or stack trace messages.   
4.       Device specification details with which you are facing the issue.   
5.       Video demonstration of the issue.   
6.       PdfViewer and Xamarin Forms version you are using at your end.   
3   
By the way, is it possible to disable the PDF default busy indicator when loading a large PDF file? Thanks.   
At present, there is no support to disable the busy indicator in Pdfviewer. Could you please share your requirement to disable the busy indicator to provide you an effective solution?   
  
 
Regards, 
Jhansi Priya Ramesh 



FT Francis Tang March 16, 2020 07:51 AM UTC

Thanks for the quick reply.

Your sample ran with no problem. However, the crash occurred, after a few repeated load and unload, when I

(1) switched to use my own PDF (see attached PDF), plus
(2) removing the toolbar etc.

Perhaps you can reproduce from your side? Thanks very much.

Francis

namespace Sample
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class PdfPage : ContentPage
    {
        public PdfPage()
        {
            this.InitializeComponent();
            pdfViewerControl.Toolbar.Enabled = false;
            pdfViewerControl.ShowPageNumber = false;
            pdfViewerControl.EnableScrollHead = false;
            var fileStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.HKCR_Radiology.pdf");
            //Load the PDF
            pdfViewerControl.LoadDocument(fileStream);
        }
        protected override void OnDisappearing()
        {
            base.OnDisappearing();
            pdfViewerControl.Unload();
        }
        private async void Button_Clicked(object sender, EventArgs e)
        {
           await Navigation.PopModalAsync();
           
        }
    }
}




Attachment: HKCR_Radiology.pdf_3b8a9117.zip


FT Francis Tang March 16, 2020 08:18 AM UTC

Sorry, just re-ran using your PDF, it also crashed.

I used the latest version of VS studio for Mac, with all nuggets updated also to latest. For real devices, I used a SamSung C7 Pro and also a Nokia 8.1, all updated with their latest versions of Android

Thanks.

Francis

Syncfusion.Pdf.PdfException: Unexpected token Real before -8176
  at Syncfusion.Pdf.IO.PdfParser.Error (Syncfusion.Pdf.IO.PdfParser+ErrorType error, System.String additional) [0x0008a] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.IO.PdfParser.Match (Syncfusion.Pdf.IO.TokenType token, Syncfusion.Pdf.IO.TokenType match) [0x00013] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.IO.PdfParser.Parse () [0x00000] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.IO.PdfParser.Parse (System.Int64 offset) [0x0000d] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.IO.CrossTable.GetObject (Syncfusion.Pdf.Primitives.IPdfPrimitive pointer) [0x0007a] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.IO.PdfCrossTable.GetObject (Syncfusion.Pdf.Primitives.IPdfPrimitive pointer) [0x0004a] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.Primitives.PdfReferenceHolder.get_Index () [0x00037] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.Primitives.PdfReferenceHolder.ObtainObject () [0x00010] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.Primitives.PdfReferenceHolder.get_Object () [0x00016] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.IO.PdfCrossTable.GetObject (Syncfusion.Pdf.Primitives.IPdfPrimitive pointer) [0x0000c] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.Parsing.PdfLoadedPageCollection.GetParentNode (System.Int32 kidStartIndex, Syncfusion.Pdf.Primitives.PdfArray kids, System.Int32 lowIndex, System.Int32 pageIndex, Syncfusion.Pdf.Primitives.PdfDictionary& node, System.Int32& localIndex, System.Boolean& isParentFetched) [0x00029] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.Parsing.PdfLoadedPageCollection.GetParent (System.Int32 index, System.Int32& localIndex, System.Boolean zeroValid, System.Boolean enableFastFetching) [0x002c9] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.Parsing.PdfLoadedPageCollection.GetPage (System.Int32 index) [0x00000] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.Pdf.Parsing.PdfLoadedPageCollection.get_Item (System.Int32 index) [0x00000] in <065e70699219434aaa8a0e6f89c1f20f>:0
  at Syncfusion.SfPdfViewer.XForms.Droid.LinearLayoutEx.InitializeLayout () [0x00046] in <2ebee7c00753460989a83aefa0c2f072>:0
  at Syncfusion.SfPdfViewer.XForms.Droid.HorizontalScrollViewEx.Initializelayout () [0x00024] in <2ebee7c00753460989a83aefa0c2f072>:0
  at Syncfusion.SfPdfViewer.XForms.Droid.ScrollViewEx.InitializeLayout () [0x00024] in <2ebee7c00753460989a83aefa0c2f072>:0
  at Syncfusion.SfPdfViewer.XForms.Droid.ScrollViewEx.OnLayout (System.Boolean changed, System.Int32 left, System.Int32 top, System.Int32 right, System.Int32 bottom) [0x003c3] in <2ebee7c00753460989a83aefa0c2f072>:0
  at Android.Widget.FrameLayout.n_OnLayout_ZIIII (System.IntPtr jnienv, System.IntPtr native__this, System.Boolean changed, System.Int32 left, System.Int32 top, System.Int32 right, System.Int32 bottom) [0x00009] in <4ccdb3137d974856b786e1aeebbfbab6>:0
  at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.36(intptr,intptr,bool,int,int,int,int)



JP Jhansi Priya Ramesh Syncfusion Team March 17, 2020 09:09 AM UTC

Hi Francis, 
 
Thank you for the details. We were able to reproduce the issue “Application crashes while loading /unloading the document continuously in Android” in our side and suspect this to be a defect. Currently we are validating this issue and we will provide further details on 19th March 2020. 
 
Regards, 
Jhansi Priya Ramesh 



FT Francis Tang March 17, 2020 02:06 PM UTC

Thank you.

Francis


JP Jhansi Priya Ramesh Syncfusion Team March 18, 2020 09:33 AM UTC

Hi Francis, 
 
Thank you for the update. As promised earlier, we will provide validation details for the issue “Application crashes while loading /unloading the document continuously in Android” on 19th March 2020. 
 
Regards, 
Jhansi Priya Ramesh 



JP Jhansi Priya Ramesh Syncfusion Team March 19, 2020 01:16 PM UTC

Hi Francis, 

We confirm that the issue “Application crashes while loading /unloading the document continuously in Android” is a defect in our side and logged defect report for the same. We will provide patch for this issue on 9th  April 2020. 

Regards, 
Jhansi Priya Ramesh 



FT Francis Tang March 23, 2020 01:57 PM UTC

Thank you.

Looking forward to this fix.

Francis


JP Jhansi Priya Ramesh Syncfusion Team March 24, 2020 05:09 AM UTC

Hi Francis, 
 
Thank you for the update. As mentioned earlier, we will provide patch for the issue “Application crashes while loading /unloading the document continuously in Android” on 9th April 2020. 
 
Regards, 
Jhansi Priya Ramesh 



AV Ashokkumar Viswanathan Syncfusion Team April 9, 2020 04:11 PM UTC

Hi Francis, 
 
The issue, "Application crashes while loading /unloading the document continuously in Android" has been fixed and the patch for this fix can be downloaded from the following location.  
 
Recommended approach - exe will perform automatic configuration
 
Please find the patch setup from below location:
 
 
 
 
Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment 
Please find the patch assemblies alone from below location:  
http://syncfusion.com/Installs/support/patch/18.1.0.42/1066109/F152387/SyncfusionPatch_18.1.0.42_1066109_4092020090304873_F152387.zip 
 
   
NuGet:   
http://syncfusion.com/Installs/support/patch/18.1.0.42/1066109/F152387/SyncfusionNuget_18.1.0.42_1066109_4092020090304873_F152387.zip 
 
   
Please find the feedback link for this from below,   

Assembly Version: 18.1.0.42
Installation Directions : 
 
This patch should replace the files “Syncfusion.SfPdfViewer.UWP.dll” under the following folder.
 
$system drive:\ Files\Syncfusion\Essential Studio\$Version # \precompiledassemblies\$Version#\4.6
 
Eg : $system drive:\Program Files\Syncfusion\Essential Studio\9.3.0.61\precompiledassemblies\9.3.0.61\4.0
 
 
To automatically run the Assembly Manager, please check the Run assembly manager
 checkbox option while installing the patch. If this option is unchecked, the patch will replace the assemblies in precompiled assemblies’ folder only. Then, you will have to manually copy and paste them to the preferred location or you will have to run the Syncfusion Assembly Manager application (available from the Syncfusion Dashboard, installed as a shortcut in the Application menu) to re-install assemblies.
 
 
Note : 
 
You can change how you receive bug fixes by navigating to the following link and updating your preferences.
 
 
https://www.syncfusion.com/support/directtrac/patches
 
 

Disclaimer : 
 
Please note that we have created this patch for version 18.1.0.42 specifically to resolve the following issue(s) reported in this/the Forum(s). 152387
 
If you have received other patches for the same version for other products, please apply all patches in the order received.
  

This fix will be included in our 2020 Vol 1 Service pack release which will be available in May 2020.
  
 
Regards, 
Ashok Kumar Viswanathan. 



PN Preethi Nesakkan Gnanadurai Syncfusion Team April 13, 2020 04:52 AM UTC

From: Francis Tang
Sent: Sunday, April 12, 2020 7:07 AM
To: Syncfusion Support <[email protected]>
Subject: Re: Syncfusion support community forum 152387, Xamarin Forms Android issues with PDF viewer, has been updated. 

  
Thanks for the update.  

I have also tried the latest version 18.1.0.43, the behaviour was the same. 


Android: 

If unload pdf control in OnDisappearing, program crashed 

If not unloading in OnDisappearing, program seemed OK 


iPhone: 

If unload pdf control in OnDisappearing, program ran but crashed after a number of repeated load and unload. (perhaps 20 times or more) 

If not unloading in OnDisappearing, program ran but getting slower and slower upon repeated load and unload. It then crashed after a number of repeated load and unload.  

Please refer to attached project which was actually a sample from you. I have changed to use my own pdf file. 

Please check for the iPhone problem there. 

Thank you. 

Francis 



PS. By the way, I use Mac VS Studio, not Windows. 

Sample



AV Ashokkumar Viswanathan Syncfusion Team April 13, 2020 08:48 AM UTC

Hi Francis,   
   
We suspect that you have tested the fix for the issue, ”Application crashes while loading /unloading the document continuously in Android” with the latest NuGet of version v18.1.043, availed in the NuGet.org. We haven’t included the fix for this issue in our latest releases. Kindly use the patch provided in version v18.1.0.42 in our last update to get the issue resolved in the Android platform.   
   
Note: Kindly follow the steps to clear the NuGet cache and then install patched NuGet to get the issue resolved.     
 
However, we could reproduce the issue, “Application crashes while loading /unloading the document continuously in iOS platform”. Currently, we are validating the issue and we will update further details on 15th April 2020.  
 
Regards, 
Ashok Kumar Viswanathan. 



AV Ashokkumar Viswanathan Syncfusion Team April 15, 2020 05:11 PM UTC

Hi Francis,   

We have confirmed that the issue “Application crashes while loading /unloading the document continuously in iOS platform” is defect and logged defect report for this issue. The patch for this issue will be delivered on 6th May 2020.  

Please find the feedback link below, 

As mentioned in our last update, Kindly confirm us whether the provided patch has resolved the issue in the Android Platform. 

Regards, 
Ashok Kumar Viswanathan. 



FT Francis Tang April 16, 2020 02:48 AM UTC

Thanks for your efforts.

I have replied on 13 April that crashes still occurred for both platforms for version 18.1.0.42 and 43. Please see above feedback.

I now also attach the same sample project but it used explicitly version 18.1.0.42, and this, as aforementioned, also has the same problems.

For Android, need to remove pdfViewerControl.Unload() in OnDisappearing() to avoid crashes when repeating load and unload the pdf.

For iPhone, please check out my reply on 13 April above.

Thanks.

Francis



Attachment: Sample_13eb9276.zip


FT Francis Tang April 16, 2020 09:14 AM UTC

Sorry, forgot one more issue:

On iPhone, double tapping on pdf will result in zooming (don't want this actually). No such behaviour on Android.

Thanks.

Francis


AV Ashokkumar Viswanathan Syncfusion Team April 16, 2020 11:27 AM UTC

Hi Francis, 

 Please find the details below, 
have replied on 13 April that crashes still occurred for both platforms for version 18.1.0.42 and 43. Please see the above feedback.   
   
I now also attach the same sample project but it used explicitly version 18.1.0.42, and this, as aforementioned, also has the same problems.   
   
For Android, we need to remove pdfViewerControl.Unload() in OnDisappearing() to avoid crashes when repeating load and unload the pdf.   
As mentioned earlier, we suspect that you have been trying the NuGet of SfPdfviewer control in product version v18.1.0.42, which is available in NuGet.org. We haven’t included the fix in the NuGet which is available in the NuGet.org. Kindly confirm whether you have installed NuGet which we have provided on 9th April 2020 or NuGet which is available in NuGet.org.   
   
   
On 9th April 2020, we have provided the patch for the issue in the version 18.1.0.42. Please find the patch link below,   
   
   
However, we could not reproduce the issue in the Android Platform with NuGet available in the above link. Please find the video illustrating the issue is resolved in the Android Platform. 
   
   
Note: Kindly follow the steps to clear the NuGet cache and then install patched NuGet to get the issue resolved.   
 
   
For iPhone, please check out my reply on 13 April above.   
As mentioned in our last update, we will provide a patch for the issue, “Application crashes while loading /unloading the document continuously in iOS platform” on 6th May 2020.   
On iPhone, double-tapping on pdf will result in zooming (don't want this actually). No such behavior on Android.   
At present, we do not have support to restrict the zooming of PDF pages on double-tap in iOS platform. Currently, we are analyzing the feasibility for the support and we will update further details on 20th April 2020.   
  
Regards, 
Ashok Kumar Viswanathan


FT Francis Tang April 16, 2020 03:01 PM UTC

Sorry, I thought I could use version 18.1.0.42 from nugget.org and missed the point that your file was not the same.

I have now switched to your version of 18.1.0.42 and the problem seemed gone. 

        protected override void OnDisappearing()
        {
            base.OnDisappearing();
            pdfViewerControl.Unload();
        }

The above code now works for Android when repetitively load and unload a pdf file.

As said and confirmed by you, the iPhone app still kept crashing after a few tries. Nevertheless, it crashed after a longer period of time if the pdf file is smaller and/or the repetitiveness is less quick.

Just a side track, it would be nice if the the Android version supports automatic fit to screen display when in landscape orientation.

On the other hand, again, the double-tapped zoom with iPhone is not consistent since we don't have this on Android. They should behave more or less the same, I guess.

Thank you.

Francis


 




AV Ashokkumar Viswanathan Syncfusion Team April 17, 2020 09:37 AM UTC

Hi Francis, 
 
Thanks for the update, 
 
Please find the details below, 
 
As said and confirmed by you, the iPhone app still kept crashing after a few tries. Nevertheless, it crashed after a longer period of time if the pdf file is smaller and/or the repetitiveness is less quick.   
As mentioned in our last update, we will provide a patch for the issue, “Application crashes while loading /unloading the document continuously in iOS platform” on 6th May 2020.    
   
We were unable to reproduce the issue, ”Application crashed after a longer period of time if the pdf file is smaller” in the iOS platform. Kindly share the following details to analyze more on this issue and assist you with a better solution.     
  1. Simple sample/ modify the above sample to reproduce the issue. 
  2. PDF document with which you have to reproduce the issue.
  3. Xamarin.Forms version 
  4. Replication procedure to reproduce the issue. 
Just a sidetrack, it would be nice if the Android version supports automatic fit to screen display when in landscape orientation.   
We were able to reproduce the issue, “PDF pages do not fit to the screen in Landscape mode” in the Android Platform with the provided information. Currently, we are validating the issue and we will update the further details on 21st April 2020.   
   
On the other hand, again, the double-tapped zoom with iPhone is not consistent since we don't have this on Android. They should behave more or less the same, I guess. 
Currently we do not have the support to zoom the PDF pages on double tap in Android platform as like in the iOS platform.  
 
 
As mentioned earlier, we will analyze the feasibility for the support to restrict the zooming of PDF pages on double-tap in iOS platform and we will update further details on 20th April 2020.    
 
Regards, 
Ashok Kumar Viswanathan. 



AV Ashokkumar Viswanathan Syncfusion Team April 21, 2020 04:44 PM UTC

  
Hi Francis, 
 
Please find the below details, 
We were able to reproduce the issue, “PDF pages do not fit to the screen in Landscape mode” in the Android Platform with the provided information. Currently, we are validating the issue and we will update the further details on 21st April 2020.    
On further analyzation,  We load the PDF document into PDF Viewer as like in below screen shot in landscape mode while implementation itself.  
 
 
Based on your requirement, we will consider it as a usability feature and will include this on volume 3 Main release 2020.  
Please find the feedback link from below,  
Currently we do not have the support to zoom the PDF pages on double tap in Android platform as like in the iOS platform.   
  
  
As mentioned earlier, we will analyze the feasibility for the support to restrict the zooming of PDF pages on double-tap in iOS platform and we will update further details on 20th April 2020.     
At present, we do not have the support for zooming on double tap gesture and option to enable/disable it programmatically in iOS Platform. we will consider it as a usability feature and we will include this on Volume 3 Main release 2020.  
 
Please track the status of the implementation from below link, 
 
As mentioned in our last update, we will provide a patch for the issue, “Application crashes while loading /unloading the document continuously in iOS platform” on 6th May 2020. Kindly provide the requested details to reproduce the issue, ”Application crashed after a longer period of time if the pdf file is smaller” in the iOS platform
 
Regards, 
Ashok Kumar Viswanathan. 



AV Ashokkumar Viswanathan Syncfusion Team May 6, 2020 01:53 PM UTC

Hi Francis, 
 
The issue with  Application crashes while loading /unloading the document continuously” in the iOS platform has been fixed and the patch for this fix can be downloaded from the following location.  
 
Please find the feedback link below, 
https://www.syncfusion.com/feedback/13346 
 
Recommended approach - exe will perform automatic configuration 
Please find the patch setup from below location:
 
http://syncfusion.com/Installs/support/patch/18.1.0.42/1066109/F152387/SyncfusionPatch_18.1.0.42_1066109_5062020030942782_F152387.exe 
 
Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment 
Please find the patch assemblies alone from below location
: 
http://syncfusion.com/Installs/support/patch/18.1.0.42/1066109/F152387/SyncfusionPatch_18.1.0.42_1066109_5062020030942782_F152387.zip 
 
NuGet: 
 
Assembly Version : 18.1.0.42 
Installation Directions :  
This patch should replace the files “Syncfusion.SfPdfViewer.UWP.dll” under the following folder. 
$system drive:\ Files\Syncfusion\Essential Studio\$Version # \precompiledassemblies\$Version#\4.6
 
Eg : $system drive:\Program Files\Syncfusion\Essential Studio\9.3.0.61\precompiledassemblies\9.3.0.61\4.0
 
 
To automatically run the Assembly Manager, please check the Run assembly manager
 checkbox option while installing the patch. If this option is unchecked, the patch will replace the assemblies in precompiled assemblies’ folder only. Then, you will have to manually copy and paste them to the preferred location or you will have to run the Syncfusion Assembly Manager application (available from the Syncfusion Dashboard, installed as a shortcut in the Application menu) to re-install assemblies. 
 
Note : 
 
You can change how you receive bug fixes by navigating to the following link and updating your preferences.
 
 
https://www.syncfusion.com/support/directtrac/patches
 
 
Disclaimer :  
Please note that we have created this patch for version 18.1.0.42 specifically to resolve the following issue(s) reported in this/the Forum. 152387
 
If you have received other patches for the same version for other products, please apply all patches in the order received.
 
This fix will be included in our 2020 Volume 2 Main release which will be available in June 2020.
  
 
 As requested earlier, kindly provide the requested details to reproduce the issue, ”Application crashed after a longer period of time if the pdf file is smaller” in the iOS platform 
 
Regards, 
Ashok Kumar Viswanathan. 



EA Elijah And May 21, 2020 04:27 PM UTC

Hello, can I download this patch also? 


AV Ashokkumar Viswanathan Syncfusion Team May 22, 2020 12:48 PM UTC

Hi Elijah, 
 
Yes, we have provided a consolidated patch in our last update for the issue “Application crashes while loading /unloading the document continuously” in the iOS and Android platforms. Please try the provided patch and let us know whether it has resolved your issue. 
 
Regards, 
Ashok Kumar Viswanathan. 


Loader.
Up arrow icon