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

Java.IO.IOException File not in PDF format or corrupted

Hello,
I have a file that I'm trying to open in the PdfViewer. If the file is corrupt, I want to cancel the operation. Right now, when I try to open a corrupt file, I get a Java.IO.IOException and the application crashes. I'm unable to catch this exception in a try/catch block. Is there a way to check to see if the file is corrupt? I've tried using File.Open and File.OpenRead, and File.ReadAllBytes, but these all work on corrupt files. I've also tried comparing the MD5 hash of a newly downloaded file and the file right before I open it, but this becomes useless when the file is edited (highlighted or free text added). 

Here is my stack trace:
Java.IO.IOException: file not in PDF format or corrupted
  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <405ad2ab226e4e74ba67db96baf95129>:0
  at Java.Interop.JniPeerMembers+JniInstanceMethods.FinishCreateInstance (System.String constructorSignature, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0004f] in <405ad2ab226e4e74ba67db96baf95129>:0
  at Android.Graphics.Pdf.PdfRenderer..ctor (Android.OS.ParcelFileDescriptor input) [0x00070] in /Users/builder/data/lanes/6102/9bf5bd5c/source/monodroid/external/xamarin-android/src/Mono.Android/obj/Release/android-28/mcw/Android.Graphics.Pdf.PdfRenderer.cs:151
  at Syncfusion.SfPdfViewer.XForms.Droid.ScrollViewEx.IsDocumentValid (Android.OS.ParcelFileDescriptor fileDescriptor) [0x00000] in <f5d188b682d844b5a33023a93f840691>:0
  at java.io.IOException: file not in PDF format or corrupted
  at at android.graphics.pdf.PdfRenderer.nativeCreate(Native Method)
  at at android.graphics.pdf.PdfRenderer.<init>(PdfRenderer.java:167)
  at at mono.java.lang.RunnableImplementor.n_run(Native Method)
  at at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
  at at android.os.Handler.handleCallback(Handler.java:873)
  at at android.os.Handler.dispatchMessage(Handler.java:99)
  at at android.os.Looper.loop(Looper.java:214)
  at at android.app.ActivityThread.main(ActivityThread.java:6981)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)

Thanks,
Kristen


1 Reply

SS Sathish Sivakumar Syncfusion Team March 12, 2019 01:42 PM UTC

Hi Kristen, 
 
Greetings from Syncfusion. 
 
We were unable to reproduce the issue “Java.IO.IOException: file not in PDF format or corrupted”, instead we are facing the exception “Syncfusion.Pdf.PdfException” while loading the corrupted PDF document in SfPdfViewer. The exception depends on the corrupted PDF document, so we suspect that the reported exception occurred only with the PDF document you are using in your end.  
 
Kindly provide us the PDF document with which the issue could be reproduced, therefore we will analyze more on this issue and provide you the better solution. 
 
Regards,
Sathish
 


Loader.
Live Chat Icon For mobile
Up arrow icon