Skip to content
This repository has been archived by the owner on Sep 19, 2019. It is now read-only.

java.io.IOException: cannot create document. Error: 3 #15

Closed
yehyatt opened this issue Jan 31, 2017 · 6 comments
Closed

java.io.IOException: cannot create document. Error: 3 #15

yehyatt opened this issue Jan 31, 2017 · 6 comments

Comments

@yehyatt
Copy link

yehyatt commented Jan 31, 2017

When I download the sample and try to run it this is the error I get :

ClassLoader referenced unknown path: /data/app/com.example.android.pdfrendererbasic-1/lib/arm
java.io.IOException: cannot create document. Error: 3

    mPdfRenderer = new PdfRenderer(mFileDescriptor);

mPdfRenderer is always null

@vijaypwr61
Copy link

Same here

@Mowahed
Copy link

Mowahed commented Apr 23, 2017

anyone found the answer for this yet ?

@vijaypwr61
Copy link

I'm using this nugget package => Xamarin.PdfView.Android.1.0.4

and I found code for Displaying pdf files instead using above [PdfRendere].

`using Com.Joanzapata.Pdfview;

namespace Physics
{
[Activity(Label = "Physics",Theme ="@style/MyTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

public class PdfPageViewer : Activity
{
    private PDFView PdfPageView;

    protected override void OnCreate(Bundle savedInstanceState)
    {


        base.OnCreate(savedInstanceState);
        Window.AddFlags(Android.Views.WindowManagerFlags.Fullscreen);
        Window.RequestFeature(Android.Views.WindowFeatures.NoTitle);

        SetContentView(Resource.Layout.PdfViewerPageLayout);

        string FilePath2 = Intent.GetStringExtra("FilePath2");
        string FilePath3 = Intent.GetStringExtra("FilePath3");

        PdfPageView = FindViewById<PDFView>(Resource.Id.PdfPageView);
        if (!string.IsNullOrEmpty(FilePath2))
        {
            PdfPageView.FromAsset(FilePath2+ ".pdf").Load();
        }
        else
        {
            PdfPageView.FromAsset(FilePath3+".pdf").Load();
        }

    }

}

}`

@sdbrannum
Copy link

sdbrannum commented Apr 27, 2017

You need to make sure the file is in the cache as the PdfRenderer can't handle the compressed file directly.
You accomplish this by:

try {
    String FILENAME = "WhateverFileYoureLookingFor.pdf";
    FileInputStream input;
    FileOutputStream output;
    final byte[] buffer = new byte[1024];
    int size;
	
    // Create file object to read and write on
    File file = new File(context.getCacheDir(), FILENAME);
	
    // check if this object exists in the cache already
    if (!file.exists()) {        

        // external directory, documents, download respectively
        // input = new FileInputStream(new File(Environment.getExternalStorageDirectory() + "/" + FILENAME));
	// input = new FileInputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/" + FILENAME));
		
        input = new FileInputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + FILENAME));
        output = new FileOutputStream(file);

	// read and write into the cache directory	
        while ((size = input.read(buffer)) != -1) {
            output.write(buffer, 0, size);
        }

	// close the streams
	input.close();
        output.close();
		
        mFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
        mPdfRenderer = new PdfRenderer(mFileDescriptor);
    }

} catch (IllegalStateException | IOException | NullPointerException e) {
    e.printStackTrace();
}

For testing sake you may want to clear your cache out at the start of this try every time. You can see how to do that in this stackoverflow question.

@telyo
Copy link

telyo commented Aug 20, 2018

my problem is
`
//if file.length ==0 while throw this exception : java.io.IOException: cannot create document. Error: 3 //so best to check yours
mFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
mPdfRenderer = new PdfRenderer(mFileDescriptor);

`

@codingjeremy
Copy link
Contributor

I am closing this issue/PR, as it has been migrated to the new repo linked above in the comments. Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants